Sign in to follow this  
Followers 0
sweept

setting a parameter through shell

17 posts in this topic

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

0

Share this post


Link to post
Share on other sites

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.QuitEnd IfstrCommand = "%COMSPEC% /c Reg add ""HKCU\Software\Microsoft\Internet Explorer\Main"" /v ""Start Page"" /d " & chr(34) & strHome & chr(34) & " /f"objShell.Run strCommand
0

Share this post


Link to post
Share on other sites
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: 1Char: 45Error: Expected end of statementCode: 800A0401Source:  Microsoft VBScript compilation error
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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 OffCLSMODE 75, 12COLOR 9FSet 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 Functionstart /wait "" %Vbs%call "%CD%\ReturnCmd.cmd"del %Vbs%del "%CD%\ReturnCmd.cmd"IF /I '%Return%'=='exit' GOTO UserCancelIF /I '%Return%'=='quit' GOTO UserCancelCLSMODE 92,5COLOR 5FEcho.Echo User URL %Return%Echo.pauseExit:UserCancelCLSCOLOR F9Mode 62,5Echo.Echo The User Has Decided To %Return%Echo So No Changes Where MadeEcho.ping -n 4 127.0.0.1>nulexit
Rename CmdVbsReturn.cmd.txt to CmdVbsReturn.cmd to make active

CmdVbsReturn.cmd.txt

0

Share this post


Link to post
Share on other sites

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)
0

Share this post


Link to post
Share on other sites

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.QuitEnd IfstrCommand = "%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
0

Share this post


Link to post
Share on other sites

This should work:

Set objShell = CreateObject("Wscript.Shell")strHome = InputBox("Provide your chosen Homepage:", "Homepage", "http://www.google.com/")If strHome = "" Then    WScript.QuitEnd IfstrCommand = "%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 & setlocalif %1' EQU ' (echo= Syntax: %~n0 [Chosen Homepage]    ) else (call :SUB %1)ping -n 8 127.0.0.1 1>nulgoto :eof:SUB(set _=%~1)echo( Your chosen homepage wasecho(    %_%
0

Share this post


Link to post
Share on other sites

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 OffCLSMODE 75, 12COLOR 9FSet 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 Functionstart /wait "" %Vbs%call "%CD%\ReturnCmd.cmd"del %Vbs%del "%CD%\ReturnCmd.cmd"CLSMODE 82,5COLOR 5FEcho.Echo User URL %Return%Echo.pauseExit
Rename CmdVbsReturn2.cmd.txt to CmdVbsReturn2.cmd to make active.

CmdVbsReturn2.cmd.txt

0

Share this post


Link to post
Share on other sites

thank you guys for the great info

I can better manage it now :)

0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites


$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"



0

Share this post


Link to post
Share on other sites

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 '?

0

Share this post


Link to post
Share on other sites


RegWrite('HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MAIN','START PAGE', "REG_SZ", $strHome)

checked ok


REG_BINARY still not applying correctly.. looking..

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.