tag:blogger.com,1999:blog-6468494060337676922.post8375705228310328155..comments2023-06-27T07:13:24.638-04:00Comments on Timothy Chen Allen: VBScript: how to run a program from vbscriptTimothy Chen Allenhttp://www.blogger.com/profile/01463492077952428825noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-6468494060337676922.post-80897931021189693932013-11-12T02:27:11.430-05:002013-11-12T02:27:11.430-05:00hmm, actually i want to run the code on the Jobs s...hmm, actually i want to run the code on the Jobs sql, after the other task is finished then i call/run the vbs, so after the step 1 is finished and then call/run the vbs,, madehttps://www.blogger.com/profile/14070595449863290744noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-5018747341974310812013-11-11T09:30:30.259-05:002013-11-11T09:30:30.259-05:00My script won't do that, but there are a coupl...My script won't do that, but there are a couple of command-line commands that will. AT (http://ss64.com/nt/at.html) and SCHTASKS (http://technet.microsoft.com/en-us/library/cc725744.aspx#BKMK_now) may be helpful. There is also a way to do this if you have access to POWERSHELL (http://www.howtogeek.com/117192/). One idea that occurs to me is that you may be able to create a task using the task scheduler on the remote PC, then use SCHTASKS RUN to make the task run from another PC. I wish I could help you more on this, but I don't have two PCs I can check this out on. Good luck; let me know how it goes!Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-76823893162242310952013-11-11T03:25:48.389-05:002013-11-11T03:25:48.389-05:00Hi timothy, i read your blog and i hope you can he...Hi timothy, i read your blog and i hope you can help me to figure the script...im still new for scripting<br /><br />my boss tell me to build some script to run .vbs from another server with vbscript too, i try this code :<br />Dim WSHShell<br /><br /> 'WSHShell = CreateObject("Wscript.Shell")<br /><br /> 'WSHShell.Run("""C:\Windows\System32\CScript.exe"" ""\\PL-SV-CRE-02\C:\Automail\RunExcel - Excel-Newconn.vbs""")<br /><br />but it doesn't work anything, i'll try this code too<br /><br />Dim WshShell<br /> Dim strScriptPath<br /><br /> WshShell = CreateObject("WScript.Shell")<br /><br /> strScriptPath = "\\PL-SV-CRE-02\C:\Automail\RunExcel - Excel-Newconn.vbs"<br /><br /> WshShell.Run("wscript.exe " & Chr(34) & strScriptPath & Chr(34), 1, vbTrue)<br /><br />and it's same doesn't work, can you help me...thank you so much timothy..madehttps://www.blogger.com/profile/14070595449863290744noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-72498970719458750592013-11-07T14:26:10.066-05:002013-11-07T14:26:10.066-05:00Dear Timothy, I'm sorry to trouble you once mo...Dear Timothy, I'm sorry to trouble you once more about the script. Is "shell(cmd)" able to run as an administrator? Unfortunately, the addiman.exe requires the cmd run as an administrator. But what's weird is that it works intermittently. In addition, I've included a few other commands to the script. (Outlook must close first in order for the other two EXEs to install.) If you have the time, would you please review and let me know what I've done wrong? Thank you very much - your help has been invaluable!!<br /><br />WScript.Sleep 20000<br /><br />strComputer = "."<br />Set objWMIService = GetObject("winmgmts:" _<br />& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")<br />Set colProcessList = objWMIService.ExecQuery _<br />("Select * from Win32_Process Where Name = 'Outlook.exe'")<br />For Each objProcess in colProcessList<br /> Set objOutlook = CreateObject("Outlook.Application")<br /> objOutlook.Quit<br />Next<br /><br />WScript.Sleep 20000<br /><br />sub shell(cmd) <br />' Run a command as if you were running from the command line<br />dim objShell<br />Set objShell = WScript.CreateObject( "WScript.Shell" )<br />objShell.Run(cmd)<br />Set objShell = Nothing<br />end sub<br /><br />shell """C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe"" WS1"<br /><br />WScript.Sleep 30000<br /><br />sub shell(cmd) <br />' Run a command as if you were running from the command line<br />dim objShell<br />Set objShell = WScript.CreateObject( "WScript.Shell" )<br />objShell.Run(cmd)<br />Set objShell = Nothing<br />end sub<br /><br />shell "\\fs01\Deployments\ContactEase\SyncUser\setup.exe"<br />Samhttps://www.blogger.com/profile/07653359473822907487noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-38816445423565481092013-11-05T15:58:25.752-05:002013-11-05T15:58:25.752-05:00Thank you so much, Timothy!!Thank you so much, Timothy!!Samhttps://www.blogger.com/profile/07653359473822907487noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-4947549836783807312013-10-30T19:31:59.840-04:002013-10-30T19:31:59.840-04:00Sam, try this. I think the problem was the quote m...Sam, try this. I think the problem was the quote marks were off, and you don't need the last line (end if):<br /><br />sub shell(cmd) <br />' Run a command as if you were running from the command line<br />dim objShell<br />Set objShell = WScript.CreateObject( "WScript.Shell" )<br />objShell.Run(cmd)<br />Set objShell = Nothing<br />end sub<br /><br />shell """C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe"" WS1"Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-1192393860297428412013-10-30T19:24:47.893-04:002013-10-30T19:24:47.893-04:00Hi Timothy,
Thank you very much for your post. I&...Hi Timothy,<br />Thank you very much for your post. I'm new to scripting, unfortunately, and I have not been successful in modifying your script to work with my particular program. I would greatly appreciate it if you would assist me in correcting whatever I've done wrong. Normally, I would go to the directory C:\Program Files (x86)\Interwoven\WorkSite, then type: addiman.exe ws1. Below is what I've modified from your example. Thank you so much!!<br /><br />sub shell(cmd) <br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run(cmd)<br /> Set objShell = Nothing<br />end sub<br /><br />shell ""C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe WS1""<br />end ifSamhttps://www.blogger.com/profile/07653359473822907487noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-1850947911532778022013-06-27T13:41:44.803-04:002013-06-27T13:41:44.803-04:00Hi Bin,
I don't think VBScript will work for t...Hi Bin,<br />I don't think VBScript will work for this. I worked on something like this before; basically, for you to be able to do sendkeys, you need a session. Sorry, I wish I had better news.Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-70742076609190028652013-06-27T07:20:59.831-04:002013-06-27T07:20:59.831-04:00Hi Timothy,
I have a scenario where I need to rest...Hi Timothy,<br />I have a scenario where I need to restart an application twice a week at 2 am. This application needs a userid and password to login. So I created a vb script which will close the application, load it, give userid and password, login and then minimize the window. And I created a scheduled task to call this script. This is in a server which runs 24X7.<br />Issue is, it works fine if it is running when I am logged in. But when I am not logged in, it just loads the application and stops there. It neither enters the credentials nor login. Seems some focussing issue. Could u help?<br />Here is my script.<br />Dim oShell<br />set oShell= Wscript.CreateObject("WScript.Shell")<br /> oShell.Run "MyApp.exe"<br />WScript.Sleep 2000<br /> oShell.Sendkeys "userid"<br /> oShell.SendKeys("{Tab}")<br /> WScript.Sleep 1000<br /> oShell.Sendkeys "password"<br /> WScript.Sleep 1000<br />oShell.SendKeys("{Enter}")<br />oShell.SendKeys "% n"<br />Wscript.Quit<br />Binhttps://www.blogger.com/profile/06592873691498527404noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-76224502231075671862013-06-13T14:42:50.882-04:002013-06-13T14:42:50.882-04:00Ucup, you want to make the command run *modally*. ...Ucup, you want to make the command run *modally*. That can be done, it requires a slight modification of the script:<br /><br />sub shell(cmd, wait)<br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run cmd, , wait<br /> Set objShell = Nothing<br />end sub<br /><br />shell "exp pass/pass@192.168.0.117:1521/orcl FILE=D:\DUMP_DATABASE\apps_v2\apps_database.dmp", true<br />'next process<br />shell "C:\"Program Files\WinSCP\WinSCP.com" /command "open apps_v2" "synchronize remote D:\DUMP_DATABASE\apps_v2 DATABASE/" exit"", false<br /><br />Notice that I put an extra parameter ("wait") in the command call, and put either true or false after the call to shell (true means wait for the command to finish). Enjoy.Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-70207060692130257532013-06-13T03:44:39.987-04:002013-06-13T03:44:39.987-04:00i have script to backup dump database..
how scri...i have script to backup dump database.. <br /><br />how script to know the process was 100% completed and continue to another process .. <br /><br />this is my script<br /><br />sub shell(cmd) <br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run(cmd)<br /> Set objShell = Nothing<br />end sub<br /><br />shell "exp pass/pass@192.168.0.117:1521/orcl FILE=D:\DUMP_DATABASE\apps_v2\apps_database.dmp"<br /><br />'next process<br />shell "C:\"Program Files\WinSCP\WinSCP.com" /command "open apps_v2" "synchronize remote D:\DUMP_DATABASE\apps_v2 DATABASE/" exit""<br />ucuphttps://www.blogger.com/profile/14209685970796745251noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-35087853203202092232013-06-10T10:40:51.175-04:002013-06-10T10:40:51.175-04:00Steve, try this:
sub shell(cmd)
' Run a comma...Steve, try this:<br />sub shell(cmd)<br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run(cmd)<br /> Set objShell = Nothing<br />end sub<br /><br />shell "D:\ITTools\PsExec.exe \\rpc13124 -c D:\ITTools\notepadstop.bat"<br /><br />As far as I can tell, you don't need all of the extra quotes, unless you are using a variable to specify the network address. If that is the case, you could do something like this:<br /><br />sub shell(cmd)<br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run(cmd)<br /> Set objShell = Nothing<br />end sub<br /><br />network_name = "\\rpc13124"<br /><br />shell "D:\ITTools\PsExec.exe " & network_name & " -c D:\ITTools\notepadstop.bat"<br /><br />A good debugging trick with this is to change the last line to:<br />msgbox "D:\ITTools\PsExec.exe " & network_name & " -c D:\ITTools\notepadstop.bat"<br /><br />Then, run the program and look at the output. If it looks like the command line you want, change "msgbox" back to "shell" and it should run correctly. Good luck!Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-82558005026664893482013-06-07T20:04:20.685-04:002013-06-07T20:04:20.685-04:00Hi Tim
I'm hoping you can help, I have a simi...Hi Tim<br /><br />I'm hoping you can help, I have a similar situation as to Omar's and I can't seem to get it working, the single line command works fine in CMD which is:<br />D:\ITTools\PsExec.exe \\ -c D:\ITTools\notepadstop.bat<br /><br /><br />I tried this but seems to try to execute PsExec in interactive mode and can't get it working<br /><br />sub shell(cmd)<br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run(cmd)<br /> Set objShell = Nothing<br />end sub<br /><br />shell """D:\ITTools\PsExec.exe"" \\rpc13124, ""-c D:\ITTools\notepadstop.bat"""<br /><br />Thanks <br /><br />SteveAnonymoushttps://www.blogger.com/profile/17518739704816635992noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-52386195893866605082012-07-01T20:33:18.815-04:002012-07-01T20:33:18.815-04:00shell "notepad test.txt"shell "notepad test.txt"BJJ4KIDShttps://www.blogger.com/profile/01105189035409710028noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-70623940007562298682011-01-18T23:15:36.386-05:002011-01-18T23:15:36.386-05:00Hey Tim, I know these posts are kindda old but was...Hey Tim, I know these posts are kindda old but was hoping you could get me some material to study VBScript? Like VBS for dummies? LOL I am really intrested in creating a little robot to run a couple of reports for me at work, but just can't seem to make it start. The middle part is easy as I can make this program record it's own VBScript and just paste it within the macro, but I have no clue how to start it.<br /><br />My email is girl_yes@yahoo.com thanks in advanceUnknownhttps://www.blogger.com/profile/14983434259163806267noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-80660393760849288602009-11-25T00:18:54.483-05:002009-11-25T00:18:54.483-05:00I am trying to use the .Run method with the argume...I am trying to use the .Run method with the arguments. how would I do this with your code please?<br /><br />object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) <br /><br />I need to say something like objShell(cmd,1,True), but compiling bombs when I try that.<br /><br />ThanksCavallhttps://www.blogger.com/profile/17807008466575786377noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-15949607650940385582009-06-09T16:51:31.403-04:002009-06-09T16:51:31.403-04:00Thanks. Your solution worked like a charm.Thanks. Your solution worked like a charm.Omarnoreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-30468900470461086672009-06-07T07:27:49.400-04:002009-06-07T07:27:49.400-04:00Omar, the problem is probably the quote marks (&qu...Omar, the problem is probably the quote marks ("). In VBScript, to make a quote appear in a string, you have to put two quotes (""). Here is the simple version script with your command:<br /><br />sub shell(cmd)<br /> ' Run a command as if you were running from the command line<br /> dim objShell<br /> Set objShell = WScript.CreateObject( "WScript.Shell" )<br /> objShell.Run(cmd)<br /> Set objShell = Nothing<br />end sub<br /><br />shell """C:\Program Files\DAEMON Tools Lite\daemon.exe"" -mount 0, ""D:\Test\Test.iso"""<br /><br />I hope that works. If it doesn't, please email me at TimothyChenAllen@gmail.com with the error message, and I'll see what I can do. Thanks!Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-69797082494795306982009-06-06T20:05:07.419-04:002009-06-06T20:05:07.419-04:00Any idea how to execute this program with switches...Any idea how to execute this program with switches and paramaters? <br />I can't get it to work for nothing.<br /><br />Here is the command:<br />"C:\Program Files\DAEMON Tools Lite\daemon.exe" -mount 0, "D:\Test\Test.iso"<br /><br />The command works fine from Command Prompt and from Run Dialog Box.<br />Just can't get it to work in a VBScript.<br />I've also tried: <br />Set objShell = CreateObject("Shell.Application")<br />objShell.ShellExecute(cmd).<br />But I have been unlucky.<br /><br />Using the command: <br />"C:\Program Files\DAEMON Tools Lite\daemon.exe"<br />works fine.<br /><br />I just can't get the syntax of switches correct.<br /><br />ThanksOmarnoreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-55038292177570079272009-06-04T16:19:10.848-04:002009-06-04T16:19:10.848-04:00Kathi, thanks so much! Sometimes I wonder if I sh...Kathi, thanks so much! Sometimes I wonder if I should keep doing this, especially since I have no idea what I'm going to do with all of these songs. I still have to put out this week's song-- I'm in Albuquerque without a guitar, so I guess this one will be a Capella.Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-41727714394494711902009-06-04T15:48:56.683-04:002009-06-04T15:48:56.683-04:00Hi Tim, I came for a peek at your code...and staye...Hi Tim, I came for a peek at your code...and stayed for the music. Your songs have touched me. Thank you :)Kathinoreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-83001978587642278652009-05-19T14:09:00.000-04:002009-05-19T14:09:00.000-04:00Thanks, GG. Come to think of it, my (ancient) lap...Thanks, GG. Come to think of it, my (ancient) laptop doesn't have USB 2.0 ports. So the newer adapters may not work for me. I'll check it out; I'm kind of tired of all my recordings starting out with a rush of white noise from my laptop.Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-27797711497424306852009-05-18T11:07:00.000-04:002009-05-18T11:07:00.000-04:00Personally I'd spend a little more cash and get yo...Personally I'd spend a little more cash and get yourself an EMU audio interface. Some complain about EMU but for the price they're pretty good. I've had a PCI EMU 0404 card for years without a problem. I think the cheapest is the EMU 0202:<br /><br />[<A HREF="http://www.amazon.com/EMU-0202-USB-Audio-Interface/dp/B000IXLH6K/ref=sr_1_1?ie=UTF8&s=electronics&qid=1242657870&sr=1-1" REL="nofollow">amazon.com</A>]<br /><br />It comes with a better selection of I/O that the Creative, including a balanced XLR mic port. More expensive versions come with a greater selection of inputs and outputs as well as MIDI ports.<br /><br />Just something to think about :)<br /><br />Oh and the only thing to watch out for is USB power. It shouldn't be a problem these days but all my old Dell laptops won't power any of my USB midi keyboards as they don't give out enough current. If that were the case you can still get yourself a PCMCIA audio interface with a break-out box for all you audio I/O.gammagoblinhttps://www.blogger.com/profile/01100143137222957254noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-36664465683168057882009-05-18T10:14:00.000-04:002009-05-18T10:14:00.000-04:00Tyler, how cool! Thanks for the advice-- I had no...Tyler, how cool! Thanks for the advice-- I had no idea that a USB-port sound card was available. I am laptop-based, too-- I'm married with a kid, so my "recording studio" is our apartment building's party room. So I lug the laptop down there to record. I will be buying one of these! Thanks for the advice!Timothy Chen Allenhttps://www.blogger.com/profile/01463492077952428825noreply@blogger.comtag:blogger.com,1999:blog-6468494060337676922.post-76451186350982588492009-05-18T09:54:00.000-04:002009-05-18T09:54:00.000-04:00Guess if I'da read through the post a bit more...Guess if I'da read through the post a bit more I'da seen where you already answered this question :) Sorry for that & thx for the response.<br /><br />That album was actually recorded completely acoustic through the air... into one of those white straw mics. The key was the sound card. At the time, I happened to be using and old PCI Sound Blaster Live card. You can probably get on one craigslist.org for $5. Because I'm laptop based now... and there's no room for a PCI card... I just recently purchased one of these... http://www.amazon.com/Creative-Labs-SB1090-Blaster-Surround/dp/B0017QQQAE and it does just as good if not better. Still using the old white straw mic I've had since 1998 :)<br /><br />Take Care -<br /><br />- TylerTyler McLaughlinhttps://www.blogger.com/profile/07985356680454790675noreply@blogger.com