Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

setting a parameter through shell

- - - - - batch

  • Please log in to reply
16 replies to this topic

#1
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
Hi, Im looking for something that will allow me to set a parameter for a batch job in a way so i can
 type something that will set a var and direct\call to batch job.  Not from set /p but from a shell box.
  
 for instance a simple batch tool that will set homepage for the browser:
 I want it to perform in a way so that it will pop a shell box, saying "set home page to ___" and have a default parameter in it, as "www.google.com" but so i can type a different feed \address to it
 
 and then this calls or sets a %var% to the hidden batch job that will run
 for instance 
 
 REG ADD HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN" /V "START PAGE" /D "%1%" /F
 or
 REG ADD HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN" /V "START PAGE" /D "%homepage_var%" /F
 
 the only emphasis is that it will redirect the parameter back to a batch job
 
 i suppose this can be achieved with vb script help and maybe some batch  help
 
 thanks in advance



How to remove advertisement from MSFN

#2
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Something like this vbscript perhaps.

Set objShell = CreateObject("Wscript.Shell")
strHome = InputBox("Provide your chosen Homepage:", "Homepage", "http://www.google.com/")
If strHome = "" Then
    WScript.Echo "User input cancelled!"
    Wscript.Quit
End If
strCommand = "%COMSPEC% /c Reg add ""HKCU\Software\Microsoft\Internet Explorer\Main"" /v ""Start Page"" /d " & chr(34) & strHome & chr(34) & " /f"
objShell.Run strCommand


#3
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
thank you Yzöwl for your reply
 
the command alone is what im interested to run from batch cmd (not from vbs)
getting what is set in the input box sent to batch (called to batch)
 
so far I have tried the script as SetHome.vbs but it throws an error
---------------------------
Windows Script Host
---------------------------
Script: SetHome.vbs 
Line: 1
Char: 45
Error: Expected end of statement
Code: 800A0401
Source:  Microsoft VBScript compilation error

 



#4
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Try to copy and paste it again! because from your error there aren't that many characters on line 1.



#5
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Here is a CMD file that builds the VBS script than creates another cmd that passes the VBS input back to the cmd window.
@Echo Off
CLS
MODE 75, 12
COLOR 9F

Set Vbs=VbsReturn.vbs 

>  %Vbs% Echo  Dim Return, Cmd, Fso, Ts
>> %Vbs% Echo   Do 
>> %Vbs% Echo    Return = Inputbox("Type In Some Web Addresss, This Must Be" ^&^_
>> %Vbs% Echo     "Longer Than 10 Character EG: WWW.123.CA" ^&vBcrlf^&_
>> %Vbs% Echo     "Type Exit Or Quit To Do Nothing")
>> %Vbs% Echo     If Instr(1,Return,"exit",1) Or Instr(1,Return,"quit",1) Then
>> %Vbs% Echo      MkCmd(Return)
>> %Vbs% Echo      Exit Do
>> %Vbs% Echo     End If
>> %Vbs% Echo     If Len(Return) ^>= 10 Then
>> %Vbs% Echo      MkCmd(Return)
>> %Vbs% Echo      Exit Do
>> %Vbs% Echo     Else
>> %Vbs% Echo      Return = ""
>> %Vbs% Echo     End If
>> %Vbs% Echo   Loop Until Len(Return) ^>= 10 
>> %Vbs% Echo    Function MkCmd(T) 
>> %Vbs% Echo     Set Fso = CreateObject("Scripting.FileSystemObject")
>> %Vbs% Echo      Cmd = "%CD%\ReturnCmd.cmd"  
>> %Vbs% Echo     Set Ts = Fso.CreateTextFile(Cmd)
>> %Vbs% Echo      Ts.WriteLine "Set Return=" ^&T
>> %Vbs% Echo      Ts.Close
>> %Vbs% Echo    End Function

start /wait "" %Vbs%

call "%CD%\ReturnCmd.cmd"

del %Vbs%
del "%CD%\ReturnCmd.cmd"

IF /I '%Return%'=='exit' GOTO UserCancel
IF /I '%Return%'=='quit' GOTO UserCancel

CLS
MODE 92,5
COLOR 5F
Echo.
Echo User URL %Return%
Echo.
pause
Exit

:UserCancel
CLS
COLOR F9
Mode 62,5
Echo.
Echo The User Has Decided To %Return%
Echo So No Changes Where Made
Echo.
ping -n 4 127.0.0.1>nul
exit
Rename CmdVbsReturn.cmd.txt to CmdVbsReturn.cmd to make active

Attached Files




GunSmokingMan



#6
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

thank you Yzöwl for your reply

 
the command alone is what im interested to run from batch cmd (not from vbs)
getting what is set in the input box sent to batch (called to batch)

The important bit for you will be this line:

strCommand = "%COMSPEC% /c Reg add ""HKCU\Software\Microsoft\Internet Explorer\Main"" /v ""Start Page"" /d " & chr(34) & strHome & chr(34) & " /f"

You would be running a command with the input parameter, (strHome)

strCommand = "YourChosenCommand " & chr(34) & strHome & chr(34)


#7
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05

 

You would be running a command with the input parameter, (strHome)

strCommand = "YourChosenCommand " & chr(34) & strHome & chr(34)

 

I'm now looking for it to run this way

 

where it will start /wait homepage.bat where there i can carry out commands

my code syntax  is of course incorrect 


Set objShell = CreateObject("Wscript.Shell")
strHome = InputBox("Provide your chosen Homepage:", "Homepage", "http://www.google.com/")
If strHome = "" Then
    Wscript.Quit
End If
strCommand = "%COMSPEC% /c "homepage.bat" "" & chr(34) & strHome & chr(34) & ""
objShell.Run strCommand

was looking at gunsmokins example where i can start the vbs from cmd 

but i want the process to quit as soon as cancel is selected ..

I too need the default address offered as in Yzöwls example

i tried looking into it but couldn't get it work as needed 


Edited by sweept, 07 March 2014 - 10:55 AM.


#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

This should work:

Set objShell = CreateObject("Wscript.Shell")
strHome = InputBox("Provide your chosen Homepage:", "Homepage", "http://www.google.com/")
If strHome = "" Then
    WScript.Quit
End If
strCommand = "%COMSPEC% /c homepage.bat " & chr(34) & strHome & chr(34)
objShell.Run strCommand

strHome will be the input parameter %1 in homepage.bat

 

Example homepage.bat​

@echo off & setlocal
if %1' EQU ' (echo= Syntax: %~n0 [Chosen Homepage]
    ) else (call :SUB %1)
ping -n 8 127.0.0.1 1>nul
goto :eof

:SUB
(set _=%~1)
echo( Your chosen homepage was
echo(    %_%


#9
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Here I modified it so when you type exit or quit it will kill the
cmd prompt window, and not report back that the user cancel.

CmdVbsReturn2.cmd
@Echo Off
CLS
MODE 75, 12
COLOR 9F

Set Vbs=VbsReturn.vbs 

>  %Vbs% Echo  Dim Return, Cmd, Fso, Ts
>> %Vbs% Echo   Do 
>> %Vbs% Echo    Return = Inputbox("Type In Some Web Addresss, This Must Be" ^&^_
>> %Vbs% Echo     "Longer Than 10 Character EG: WWW.123.CA" ^&vBcrlf^&_
>> %Vbs% Echo     "Type Exit Or Quit To Do Nothing")
>> %Vbs% Echo     If Instr(1,Return,"exit",1) Or Instr(1,Return,"quit",1) Then
>> %Vbs% Echo      CreateObject("Wscript.Shell").Run("Taskkill /F /IM cmd.exe /T"),0,true 
>> %Vbs% Echo      Wscript.Quit(1)
>> %Vbs% Echo     End If
>> %Vbs% Echo     If Len(Return) ^>= 10 Then
>> %Vbs% Echo      MkCmd(Return)
>> %Vbs% Echo      Exit Do
>> %Vbs% Echo     Else
>> %Vbs% Echo      Return = ""
>> %Vbs% Echo     End If
>> %Vbs% Echo   Loop Until Len(Return) ^>= 10 
>> %Vbs% Echo    Function MkCmd(T) 
>> %Vbs% Echo     Set Fso = CreateObject("Scripting.FileSystemObject")
>> %Vbs% Echo      Cmd = "%CD%\ReturnCmd.cmd"  
>> %Vbs% Echo     Set Ts = Fso.CreateTextFile(Cmd)
>> %Vbs% Echo      Ts.WriteLine "Set Return=" ^&T
>> %Vbs% Echo      Ts.Close
>> %Vbs% Echo    End Function

start /wait "" %Vbs%

call "%CD%\ReturnCmd.cmd"

del %Vbs%
del "%CD%\ReturnCmd.cmd"


CLS
MODE 82,5
COLOR 5F
Echo.
Echo User URL %Return%
Echo.
pause
Exit
Rename CmdVbsReturn2.cmd.txt to CmdVbsReturn2.cmd to make active.
Attached File  CmdVbsReturn2.cmd.txt   1.28KB   0 downloads


GunSmokingMan



#10
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05

thank you guys for the great info

I can better manage it now :)



#11
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
another question 
is there a way to make double click in the text capture\highlight between fragments of the text with this vb box
or some other tool that will do it
 
http://www. [highlight]google[highlight].com/

Edited by sweept, 07 March 2014 - 04:04 PM.


#12
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
It would help if you posted any code you have written because I really do not understand what you want now.

Here a way to query Google and get some results
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Query
  Do
   Query = InputBox("Type In The Search Word To Use On Google.com?" &vbCrLf&_
                    "To Do Nothing Type Exit Or Quit")
    If InStr(1,Query,"exit",1) Or InStr(1,Query,"quit",1) Then
     WScript.Quit(1)
    ElseIf Len(Query) >= 2 Then
     Act.Run("http://www.google.com/search?q="&Query),1,False
     WScript.Quit(2)
    Else
     Query = ""
    End If     
  Loop Until Len(Query) = 1000



GunSmokingMan



#13
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
$strHome = InputBox("HOmepage","Provide your chosen Homepage","https://www.google.com/")
if $strHome == "" then Exit
   RegWrite("HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN", "START PAGE", "REG_SZ", "$strHome")
   RegWrite('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections','DefaultConnectionSettings',"REG_BINARY","3c000000110000000100000000000000000000000000000001000000000000000000000000000000000000000000000000000000")

$SED=(@ScriptDir & "\sed.exe")
$path = EnvGet("USERPROFILE") & "\Local Settings\Application Data\Google\Chrome\User Data\Default\Preferences"

If FileExists($Path) Then
   RunWait(@ComSpec & " /K " & '.\sed.exe -i "/invalidator/i \   \"homepage\": \"$strHome&\",\n\   \"homepage_is_newtabpage\": false," " '&$path&'', "", @SW_SHOW)
EndIf
I'm now trying to incorporate this into autoit
but I'm having trouble with the command strings ..
for the sed.exe command I'm using sed for windows ..
 
the one with the RegWrite REG_BINARY it is aimed to tick off  "automatically detect settings" in IE. but it is also adding none wanted digits to the proxy server settings
from cmd it is adjusted correctly as so:
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" /f /v "DefaultConnectionSettings" /t REG_BINARY /d 3c000000110000000100000000000000000000000000000001000000000000000000000000000000000000000000000000000000"
 


#14
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

   RegWrite("HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN", "START PAGE", "REG_SZ", "$strHome")
   RegWrite('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections','DefaultConnectionSettings',"REG_BINARY","3c000000110000000100000000000000000000000000000001000000000000000000000000000000000000000000000000000000")

" or '?



#15
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
  
 RegWrite('HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN','START PAGE', "REG_SZ", $strHome)
checked ok
 
REG_BINARY still not applying correctly.. looking..


#16
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

It's inconsistent even with the line directly before it!

 

That said, the RegWrite method in vbscript does not support writing binary data greater than four bytes so perhaps AuitoIt has a similar restriction.

 

You may also be better advised to use the APPDATA environment variable as opposed to USERPROFILE with \Local Settings\Application Data



#17
MHz

MHz

    Just simple

  • Member
  • PipPipPipPipPipPipPip
  • 1,659 posts
  • Joined 02-August 04
  • OS:Windows 7 x64
  • Country: Country Flag

If you are going to use AutoIt, then the variables will not expand within strings unless you set some options to do that. Binary data in AutoIt starts with 0x so it is like 0x3C00...

 

Here is the correction to your Input and the following RegWrites. The underscores at the end of the lines are continuations characters so the lines do not go off page.

$strHome = InputBox("HOmepage", "Provide your chosen Homepage", "https://www.google.com/")
if $strHome == "" then Exit 1
RegWrite("HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN", "START PAGE", "REG_SZ", $strHome)
RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections', _
	'DefaultConnectionSettings', "REG_BINARY", _
	"0x3c000000110000000100000000000000000000000000000001000000000000000000000000000000000000000000000000000000" _
)

As for your your use of sed, well, that is not clear to my understanding of what you are doing. AutoIt has got Perl Compatible Regular Expression (PCRE) support built in so perhaps you can use FileRead to read the file and use StringRegExpReplace to do the replacements in the string and then use FileWrite to write to the file with the changes. :)







Also tagged with one or more of these keywords: batch

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users