![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Create a path string Hello I've got a program that I run quite a few times, and I've been doing it via cmd line, and I'd like to create a VBscript and use wshshell.run to excute this. I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe disable "Local Area Connection" Now I can't seem to get my path correct for wshshell.run I think whats really giving me issues is that I need "" around the Local Area Connection. I've got a variable setup for the program path Const Mystring = "c:\Program Files\Some Folder\program.exe" then Const Constring = "Local Area Connection " wshShell.run Mystring & " disable " & """ & connectionstring & """", 3, true Any ideas on the correct way to do this? Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Create a path string "John Denver" <nospam@xxxxxx> wrote in message news:OB%23%23$TGuJHA.4632@xxxxxx Quote: > Hello > > I've got a program that I run quite a few times, and I've been doing it > via cmd line, and I'd like to create a VBscript and use wshshell.run to > excute this. > > > I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe > disable "Local Area Connection" > > Now I can't seem to get my path correct for wshshell.run I think whats > really giving me issues is that I need "" around the Local Area > Connection. > > I've got a variable setup for the program path > > Const Mystring = "c:\Program Files\Some Folder\program.exe" then > Const Constring = "Local Area Connection " > > wshShell.run Mystring & " disable " & """ & connectionstring & """", 3, > true > > > Any ideas on the correct way to do this? > > Thanks answer is a humble batch file: @echo off "c:\Program Files\Some Folder\program.exe" disable "Local Area Connection" |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Create a path string "John Denver" <nospam@xxxxxx> wrote in message news:OB%23%23$TGuJHA.4632@xxxxxx Quote: > Hello > > I've got a program that I run quite a few times, and I've been doing it > via cmd line, and I'd like to create a VBscript and use wshshell.run to > excute this. > > > I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe > disable "Local Area Connection" > > Now I can't seem to get my path correct for wshshell.run I think whats > really giving me issues is that I need "" around the Local Area > Connection. > > I've got a variable setup for the program path > > Const Mystring = "c:\Program Files\Some Folder\program.exe" then > Const Constring = "Local Area Connection " > > wshShell.run Mystring & " disable " & """ & connectionstring & """", 3, > true > > > Any ideas on the correct way to do this? > > Thanks > in a quotes string must be doubled. I would try something similar to: strCmd = "%comspec% /c ""c:\Program Files\Some Folder\program.exe"" disable ""Local Area Connection""" Wscript.Echo "Command to run: " & strCmd Set wshShell = CreateObject("Wscript.Shell") wshShell.Run strCmd, 3, True The Wscript.Echo statement is for troubleshooting, but it should display what will be run. The %comspec% ensures that the correct command processor for your OS is used, the /c closes the command shell when the command completes. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Create a path string Const Mystring = "c:\Program Files\Some Folder\program.exe" Const Constring = "Local Area Connection " Set WSH = CreateObject("WScript.Shell") WSH.Run(escape(Mystring) & " " & Chr(34) & Constring & Chr(34)) |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Create a path string gimme_this_gimme_that@xxxxxx schrieb: Quote: > Const Mystring = "c:\Program Files\Some Folder\program.exe" > Const Constring = "Local Area Connection " > Set WSH = CreateObject("WScript.Shell") > WSH.Run(escape(Mystring) & " " & Chr(34) & Constring & Chr(34)) (1) Richard Mueller's solution to understand, why double quotes are needed for the file specification of the executable (2) the VBScript Docs, Topic "Escape Function" to understand, why the use of the Escape function is misguided (3) the VBScript Docs, Topic "VBScript Procedures" to understand, why the () in the .Run statement are wrong/misleading |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Create a path string Quote: > (1) Richard Mueller's solution to understand, why double quotes > * * *are needed for the file specification of the executable Quote: > (2) the VBScript Docs, Topic "Escape Function" to understand, why > * * *the use of the Escape function is misguided corrupted? Quote: > (3) the VBScript Docs, Topic "VBScript Procedures" to understand, > * * *why the () in the .Run statement are wrong/misleading |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Create a path string Thanks for the tips, got it working. now, will the WshShell.run return me the completion status of c:\Program Files\Some Folder\program.exe "John Denver" <nospam@xxxxxx> wrote in message news:OB%23%23$TGuJHA.4632@xxxxxx Quote: > Hello > > I've got a program that I run quite a few times, and I've been doing it > via cmd line, and I'd like to create a VBscript and use wshshell.run to > excute this. > > > I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe > disable "Local Area Connection" > > Now I can't seem to get my path correct for wshshell.run I think whats > really giving me issues is that I need "" around the Local Area > Connection. > > I've got a variable setup for the program path > > Const Mystring = "c:\Program Files\Some Folder\program.exe" then > Const Constring = "Local Area Connection " > > wshShell.run Mystring & " disable " & """ & connectionstring & """", 3, > true > > > Any ideas on the correct way to do this? > > Thanks > > > > > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Create a path string In some cases, yes. If the program returns an exit code and does not spawn another process, you can retrieve the exit code. A zero would indicate no error. For example: intError = wshShell.Run(strCmd, 3, True) Wscript.Echo "Exit code: " & CStr(intError) You must use True as the third parameter (indicating to wait for the program to complete) for this to work. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "John Denver" <nospam@xxxxxx> wrote in message news:%23AUy6VJuJHA.5172@xxxxxx Quote: > Thanks for the tips, got it working. > > now, will the WshShell.run return me the completion status of c:\Program > Files\Some Folder\program.exe > > > "John Denver" <nospam@xxxxxx> wrote in message > news:OB%23%23$TGuJHA.4632@xxxxxx Quote: >> Hello >> >> I've got a program that I run quite a few times, and I've been doing it >> via cmd line, and I'd like to create a VBscript and use wshshell.run to >> excute this. >> >> >> I normally type from a cmd prompt c:\Program Files\Some >> Folder\program.exe disable "Local Area Connection" >> >> Now I can't seem to get my path correct for wshshell.run I think whats >> really giving me issues is that I need "" around the Local Area >> Connection. >> >> I've got a variable setup for the program path >> >> Const Mystring = "c:\Program Files\Some Folder\program.exe" then >> Const Constring = "Local Area Connection " >> >> wshShell.run Mystring & " disable " & """ & connectionstring & """", 3, >> true >> >> >> Any ideas on the correct way to do this? >> >> Thanks >> >> >> >> >> >> > |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Create a path string <gimme_this_gimme_that@xxxxxx> wrote in message news:0acb211c-e855-471b-8740-1618ecb1dbac@xxxxxx Quote: > (2) the VBScript Docs, Topic "Escape Function" to understand, why > the use of the Escape function is misguided corrupted? Hi, gimme What exactly do you mean about the script56.chm's being corrupted? Maybe it is just a security problem. Here is an example: You go to msdn.microsoft.com and do a search that results in a URL like the following: http://www.microsoft.com/downloads/e...&stype=s_basic This gives you a list of about 80 .CHM-related links. You might click on a link like: Windows PowerShell Graphical Help File (Version 2.0) which in this case links you to a page with a download button. The file downloaded is PowerShell2Help.exe, which turns out to be a self-extracting ZIP file. The extracted file is named PowerShell.chm. When you double click PowerShell.chm, you get a security warning that mentions that the publisher is unknown, and you have the choices of 'Open' or 'Cancel'. Open attempts to open the help file, and the left pane looks like a normal contents list, but the right pane says Action canceled and has a useless 'Please try the following:" suggestion. Here is the secret. Right click PowerShell.chm, and choose 'Properties'. Near the bottom of the properties window, you will probably see a Security entry that says this file came from another computer and might be blocked to help protect this computer, followed by an "Unblock" button. After you click the Unblock button and choose 'apply', this security info area is grayed out or is removed. The help file should then open and display properly with no questions asked. -Paul Randall |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Create a path string gimme_this_gimme_that@xxxxxx schrieb: For reference: gimme_this_gimme_that@xxxxxx schrieb: Quote: > Const Mystring = "c:\Program Files\Some Folder\program.exe" > Const Constring = "Local Area Connection " > Set WSH = CreateObject("WScript.Shell") > WSH.Run(escape(Mystring) & " " & Chr(34) & Constring & Chr(34)) Quote: Quote: >> (1) Richard Mueller's solution to understand, why double quotes >> are needed for the file specification of the executable > Isn't char(34) and a double quote the same thing? the file specification of the executable *as well*. Quote: Quote: >> (2) the VBScript Docs, Topic "Escape Function" to understand, why >> the use of the Escape function is misguided > Did you know the script56.chm, the "VBScript Docs" document at M$ is > corrupted? string so it contains only ASCII characters". If you apply this function to a path WScript.Echo Escape("c:\Program Files\Some Folder\program.exe") ==> c%3A%5CProgram%20Files%5CSome%20Folder%5Cprogram.exe the result is not suitable for .Run or .Exec. Quote: Quote: >> (3) the VBScript Docs, Topic "VBScript Procedures" to understand, >> why the () in the .Run statement are wrong/misleading > What I posted works. I thought the OP wanted a solution. Not you. calling Sub is wrong. The code I cited above is no solution. Quality of code does not depend on the person you give it to. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Extracting drive, path, filebasename WITH string functions and NOT system function ??? | VB Script | |||
| Create Directory on a UNC Path | PowerShell | |||
| Extract folder from dir path (String) | PowerShell | |||
| How do I escape the wildcard character in a path string? | PowerShell | |||