How to run a .bat file on a log script

Discussion in 'Software' started by Lunatic, Mar 27, 2009.

  1. Lunatic

    Lunatic Private E-2

    This is my loging script it work great. BUT i want to run a .bat file also (this is the batch file name update.bat).Any ideas? I'm using server 2003 and everyone has xp. How can i run a batch file during login?

    Thank You in advance.



    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.AddWindowsPrinterConnection "\\server name\printer name"
    objNetwork.AddWindowsPrinterConnection "\\server name\printer name"


    On Error Resume Next
    objNetwork.MapNetworkDrive "G:" , "\\server name\folder name"

    objNetwork.MapNetworkDrive "I:" , "\\server name\folder name" & "\" & objNetwork.UserName

    objNetwork.MapNetworkDrive "Z:" , "\\server name\folder name"

    objNetwork.MapNetworkDrive "S:" , "\\server name\folder name" & "\" & objNetwork.UserName




    Wscript.Quit


    :cry
     
  2. PC-XT

    PC-XT Master Sergeant

    I usually end up translating bat files into scripts, but I often use Wscript.shell's run or exec command to run them. In VBScript, this would be
    Code:
    Set WSHShell = CreateObject("Wscript.Shell")
    WSHShell.Run ("c:\startup.bat")
    There are other parameters for these commands to run the script in the background, for instance
    Code:
    WSHShell.Run "startup.bat",0,true
    will run in background (the 0 does this, or you can use vbhide instead) and the last true/false tells whether to wait for the command to finish before continuing the script.

    I've also heard this will work:
    Code:
    shell "c:\thebatchfile.bat",0
     
    Last edited: Mar 28, 2009
  3. Lunatic

    Lunatic Private E-2

    Could you tell me where would I but this on my script. (Set WSHShell = CreateObject("Wscript.Shell")
    WSHShell.Run ("c:\startup.bat"))?





    Set WSHShell = CreateObject("Wscript.Shell")
    WSHShell.Run ("c:\startup.bat")

    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.AddWindowsPrinterConnection "\\server name\printer name"
    objNetwork.AddWindowsPrinterConnection "\\server name\printer name"


    On Error Resume Next
    objNetwork.MapNetworkDrive "G:" , "\\server name\folder name"

    objNetwork.MapNetworkDrive "I:" , "\\server name\folder name" & "\" & objNetwork.UserName

    objNetwork.MapNetworkDrive "Z:" , "\\server name\folder name"

    objNetwork.MapNetworkDrive "S:" , "\\server name\folder name" & "\" & objNetwork.UserName




    Wscript.Quit
     
  4. Lunatic

    Lunatic Private E-2


    My batch file is located in a difrent server also \\server name\folder name\update.bat How can i put this on my script. Thank You
     
  5. PC-XT

    PC-XT Master Sergeant

    To access the different server, just use "\\server name\folder name\update.bat" instead of "C:\update.bat". You place the WSHShell.run command in the position you want the bat file to run. The set WSHShell command should go somewhere before it. The Wscript.shell also has other things I use, so I usually place that set statement very near the top to prepare for the rest of the script. I think you could merge them into
    Code:
    CreateObject("Wscript.Shell").Run("\\server name\folder name\update.bat",0)
    or use the shell command
    Code:
    shell "\\server name\folder name\update.bat",0
    if you don't want to use set. If you want, you can include a third parameter of true to have the script wait for the batch file to finish. A false value, which is the default, will have it run the batch file as a separate process, and keep running the script at the same time the batch file is running.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds