# Help! VB Script that starts running a program



## networkguy12345 (Sep 2, 2010)

I have a very limited background into programming. I need a vb script that will have a message box pop up when you click on the script icon asking if the user wants to start the program (Yes or No)...of course if the click yes then the program starts...but if no then it just exits. Any ideas? 


Thanks.


----------



## networkguy12345 (Sep 2, 2010)

The Message Box works but how do you tie together by clicking "Yes" it starts running the program fsav.exe?



Option Explicit 

Dim MessageBox
Dim RunScan 


RunScan = "C:\Program Files\F-Secure\Anti-Virus\fsav.exe"

MessageBox = MsgBox("Run Anti-Virus Scan Now?", _
vbYesNoCancel + vbQuestion, _
"F-Secure")


If MessageBox = "Yes" Then
Run RunScan
End If


----------



## AlbertMC2 (Jul 15, 2010)

Hi

Try this - substitute Excel for F-Secure.

```
Option Explicit

Sub Run(ByVal sFile)
   Dim shell
   Set shell = CreateObject("WScript.Shell")
   shell.Run Chr(34) & sFile & Chr(34), 1, false
   Set shell = Nothing
End Sub

Dim MessageBox
Dim RunScan

RunScan="C:\Program Files\Microsoft Office\Office12\EXCEL.EXE"

MessageBox=MsgBox("Run Excel Now?",vbYesNo,"Excel")

If MessageBox=6 Then
   Run RunScan
End If
```


----------



## networkguy12345 (Sep 2, 2010)

Thank you for your reponse...I was unable to run the program due to it coming back with a "C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" destination folder cannot be found. I was getting the same message when I typed in the location of the F-Secure exe file. Both cases seem to have the correct location of exe files like I said. Any idea why this is happening?


----------



## AlbertMC2 (Jul 15, 2010)

Hi

I am not really sure. Are you including the quotation marks surrounding the path and file name (" ") ?
If you copy* "C:\Program Files\F-Secure\Anti-Virus\fsav.exe"* and paste it in *Start* -> *run *and then enter does F-Secure run?
Is fsav.exe a Windows or DOS program?


----------



## networkguy12345 (Sep 2, 2010)

Yes, I'm including the quatations marks surrounding the path and file name. If I run that "C:\Program Files\F-Secure\Anti-Virus\fsav.exe" in a batch script to see whats going on I'm getting a "The system cannot find the file specified error." Fsav is a Windows program I believe.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

So let me get this straight. If you go to *Start *-> *Run *and type in 

```
[B]"C:\Program Files\F-Secure\Anti-Virus\fsav.exe"[/B]
```
and then press *enter *(*OK*) it still gives a "_Cannot find the file_" error?


----------



## Squashman (Apr 14, 2005)

What version of Windows are you running?


----------



## networkguy12345 (Sep 2, 2010)

Well I was getting the "Cannot find the file" error when I was running command above with runas added so I could see whats going on....it was just openning a command prompt window for a second and then closing it with just the command....I had task manager opened but the fsav.exe never was started....Windows XP SP3


----------



## networkguy12345 (Sep 2, 2010)

Here lies the issue....it is looking for a set of parameters after the command line scanner file fsave.exe. It runs when I manually put in the following commands in a command prompt:


C:\Program Files\F-Secure\Anti-Virus> fsave.exe /HARD /REPORT=C:\PROGRA~1\F-SECURE\ANTI-V~1\REPORT.TXT /USEACCOUNT


----------



## networkguy12345 (Sep 2, 2010)

How could I add those needed parameters in there? I've tried this script and it does not seem to kick off an anti-virus scan: 

Option Explicit

Sub Run(ByVal sFile)
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false 
Set shell = Nothing
End Sub

Dim MessageBox
Dim RunScan


RunScan="C:\Program Files\F-Secure\Anti-Virus\fsav.exe" & "/HARD /REPORT=C:\PROGRA~1\F-SECURE\ANTI-V~1\REPORT.TXT /USEACCOUNT"
MessageBox=MsgBox("Run Anti-Virus Scan Now?",vbYesNo,"F-Secure")

If MessageBox= VbYes Then
Run RunScan
End If

Getting an error on the shell.run line: "The system cannot find the file specified" 
What is that line really saying?


----------



## AlbertMC2 (Jul 15, 2010)

Hi

Try:

```
Option Explicit

Sub Run(ByVal sFile)
   Dim shell
   Set shell = CreateObject("WScript.Shell")
   shell.Run sFile, 1, false 
   Set shell = Nothing
End Sub

Dim MessageBox
Dim RunScan

RunScan=chr(34) & "C:\Program Files\F-Secure\Anti-Virus\fsav.exe" & chr(34) & " /HARD /REPORT=C:\PROGRA~1\F-SECURE\ANTI-V~1\REPORT.TXT /USEACCOUNT"

MessageBox=MsgBox("Run Anti-Virus Scan Now?",vbYesNo,"F-Secure")

If MessageBox= VbYes Then
   Run RunScan
End If
```


----------



## networkguy12345 (Sep 2, 2010)

That seems to be working! Thanks a lot for you help with that....I apreciate it.


----------



## networkguy12345 (Sep 2, 2010)

*Re: [SOLVED] Help! VB Script that starts running a program*

One more thing...I'm trying to add a line at the end that when the scan gets completed it brings up a box saying "Scan Completed." Whats the best way to go about that? Ive tried a few things but its not working how I want it to. Thanks again!


----------



## AlbertMC2 (Jul 15, 2010)

*Re: [SOLVED] Help! VB Script that starts running a program*

Hi

Try:

```
Option Explicit

Sub Run(ByVal sFile)
   Dim shell
   Set shell = CreateObject("WScript.Shell")
   shell.Run sFile, 1, false 
   Set shell = Nothing
End Sub

Dim MessageBox, RunScan, Running, Processes

Running = True

RunScan=chr(34) & "C:\Program Files\F-Secure\Anti-Virus\fsav.exe" & chr(34) & " /HARD /REPORT=C:\PROGRA~1\F-SECURE\ANTI-V~1\REPORT.TXT /USEACCOUNT"

MessageBox=MsgBox("Run Anti-Virus Scan Now?",vbYesNo,"F-Secure")

If MessageBox= VbYes Then
   Run RunScan
   Do Until Not Running '= False
      Set Processes = GetObject( _
                         "winmgmts:{impersonationLevel=impersonate}" _
                         ).ExecQuery( "Select * From Win32_Process Where Name = 'FSAV.EXE'")
      WScript.Sleep 1000
      If Processes.Count = 0 Then 
         Running = False
         MessageBox=MsgBox("F-Secure Scan Completed",vbOkOnly,"F-Secure")
      End If
   Loop
End If
```


----------



## networkguy12345 (Sep 2, 2010)

*Re: [SOLVED] Help! VB Script that starts running a program*

Well turns out I need to be able to run this script under an non-admin account...when I try to go run it under a non-admin account it does not start scanning at all. So I'll need to add some lines that will allow me to do this...I've set up a local admin account to just use for this script (None of are employees have admin privs on their machines). I've tried several different things but doesn't seem to work with the above script I have...any ideas?? I wanted to just have it still pop up with a window asking to start scan and then automatically accepted admin username/password and then begin scanning...


----------



## AlbertMC2 (Jul 15, 2010)

Hi

You can try this although I doubt it will work. For the RunScan variable try:

```
RunScan="runas /user:UserName " & chr(34) & "C:\Program Files\F-Secure\Anti-Virus\fsav.exe" & chr(34) & " /HARD /REPORT=C:\PROGRA~1\F-SECURE\ANTI-V~1\REPORT.TXT /USEACCOUNT"
```
where UserName is the username of an account with Admin privileges.
Once it starts it will ask for a password for the UserName account

I actually think you will have to right click the file and select "Run As Administrator"
I also know that winmgmt needs to run in an elevated command prompt.


----------



## networkguy12345 (Sep 2, 2010)

Yeah it doesn't seem to work....right-clicking on the file to selet "Run As" doesn't work either (not listed as an option). Any other ideas or things to try?


Thanks again for the help.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

You can make another VB script file that runs the VBS file you have already written:


```
Option Explicit

Dim Shell, sCurPath
Set Shell = CreateObject("Shell.Application")
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Shell.ShellExecute "wscript.exe", Chr(34) & sCurPath & "\2.VBS" & Chr(34), "", "runas", 1
Set shell = Nothing
```
Note 2.VBS is the name of the VB Script you have already written. So if you have named it something else you will have to change it.

What this does it open the script as an elevated user. Therefore UAC will ask if you want to run the script. Once you say "YES" the 2nd script will launch asking if you want to run FSAV etc as before.
Note that both scripts must be copied in to the same directory/folder.


----------



## networkguy12345 (Sep 2, 2010)

Yes that works!


----------

