Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: vbscript shell.run help....  (Read 37262 times)

0 Members and 1 Guest are viewing this topic.

blastman

    Topic Starter


    Hopeful

    vbscript shell.run help....
    « on: June 06, 2008, 05:02:20 AM »
    hi guys,

    The code below is used to remotely install 0ffice 2007 viewer. It does work but it has some bugs and I'm hoping that you guys might be able to help me out.....


    the 'shell.run' line (in red) doesn't wait for the batch file to finish before continuing the script. I've checked and re checked the run line and it all seems fine but it still won't wait until it's finished.

    Any ideas???


    '
    '   Script to remotely install Office 2007 viewer
    '
    '
    '
    'setting objects
    Dim net, objFSO, shell

    Set net = CreateObject("wscript.network")
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set shell = CreateObject("wscript.shell")

    'getting IP address
    IP=InputBox("Enter the IP or computer name of remote machine:", "Install Office 2007 Viewer Script")

    'Mapping drive to source folder
    If (objFSO.DriveExists("X:") = False) Then
       net.MapNetworkDrive "X:", "\\basdc01\it\my name\scripts"
    End If

    'mapping drive to remote machine
    net.MapNetworkDrive "Z:", "\\" & IP & "\c$"

    'creating folder for install exe on remote machine
    If (objFSO.FolderExists("Z:\2007_viewer") = False) Then
       objFSO.CreateFolder "Z:\2007_viewer"
    End If

    'copying exe to remote machine
    objFSO.CopyFile "X:\2007_viewer\viewer.exe", "Z:\2007_viewer\viewer.exe"

    'creating app variable to incudle IP
    app = "C:\scripts\install_viewer.bat " & IP

    'echoing for confrimation - commented out as not needed
    'WScript.Echo app

    'running batch to install (should wait for it to finish before going to next step)
    shell.Run app, 1, True

    'checking if fail file is present (indercating that install failed - echoing messages to screen to say such.
    If (objFSO.FileExists("Z:\installfailed.txt") = True) Then
       WScript.echo "Unable to install Viewer. Please check network connections and try again"
       objFSO.DeleteFile "Z:\installfailed.txt"
       Else
       WScript.Echo ("Office 2007 Viewer Install on " & IP & " on " & Time & " " & Date)
    End If

    'starting batch file to send message to remote machine about completation of script
    shell.Run "C:\scripts\NetSend07viewer.bat " & IP, true

    'removing mapped drives
    net.RemoveNetworkDrive "Z:"
    net.RemoveNetworkDrive "X:"

    'quit
    wscript.quit

    Blastman, you are the man. Thank You Very Much!!!!!!!!!



    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: vbscript shell.run help....
    « Reply #1 on: June 06, 2008, 06:24:33 AM »
    Quote
    shell.Run app, 1, True

    Quote
    app = "C:\scripts\install_viewer.bat " & IP

    It might be helpful to see the contents of install_viewer.bat. It could be the batch file started up a secondary process, terminated, and returned control to the VBScript.

    Quote
    shell.Run "C:\scripts\NetSend07viewer.bat " & IP, true

    I believe you're missing a comma in this line.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    blastman

      Topic Starter


      Hopeful

      Re: vbscript shell.run help....
      « Reply #2 on: June 06, 2008, 06:39:05 AM »
      [
      Quote
      shell.Run "C:\scripts\NetSend07viewer.bat " & IP, true

      I believe you're missing a comma in this line.

      That one seems to be working fine ??!!??

      install_viewer.bat;

      Code: [Select]
      @echo off

      start /wait /b e:\"my stuff"\pstools\psexec \\%1 c:\2007_viewer\viewer.exe /quiet


      if %errorlevel% gtr 0 (goto fail)

      exit


      :fail

      echo FAil >>\\%1\c$\installfailed.txt

      exit

      Blastman, you are the man. Thank You Very Much!!!!!!!!!



      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: vbscript shell.run help....
      « Reply #3 on: June 06, 2008, 07:07:42 AM »
      Seems like the start command cranks up psexec which in turn cranks up viewer.

      Question 1: Who has control? After psexec cranks up  viewer does psexec terminate immediately and return control to the start command? Or does psexec wait for viewer to terminate before terminating itself?

      Question 2: Is the errorlevel returned from the start command or psexec?  Highly unlikely it's from viewer.

      Once the batch file terminates, return reverts to the VBScript and life goes on as we know it.

      Try inserting a pause after the start command, and use the task manager to see if viewer is still executing. I realize your logic is for a network, but you may have to debug on the local machine.

       8)

      PS. Is any of this related to this post?
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      blastman

        Topic Starter


        Hopeful

        Re: vbscript shell.run help....
        « Reply #4 on: June 06, 2008, 07:30:24 AM »
        cheers for the reply;

        1 - psexec starts viewer and then waits for it to exit (by defult) before returning control.
        2 - the error level comes from the remote program.

        I've already put a pause in after the start line but to no effect.

        psexec /? >>

        PsExec executes a program on a remote system, where remotely executed console
        applications execute interactively.

        Usage: psexec [\\computer[,computer2[,...] | @file][-u user [-p psswd]][-n s][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
             -a         Separate processors on which the application can run with
                        commas where 1 is the lowest numbered CPU. For example,
                        to run the application on CPU 2 and CPU 4, enter:
                        "-a 2,4"
             -c         Copy the specified program to the remote system for
                        execution. If you omit this option the application
                        must be in the system path on the remote system.
             -d         Don't wait for process to terminate (non-interactive).
             -e         Does not load the specified account's profile.
             -f         Copy the specified program even if the file already
                        exists on the remote system.
             -i         Run the program so that it interacts with the desktop of the
                        specified session on the remote system. If no session is
                        specified the process runs in the console session.
             -l         Run process as limited user (strips the Administrators group
                        and allows only privileges assigned to the Users group).
                        On Windows Vista the process runs with Low Integrity.
             -n         Specifies timeout in seconds connecting to remote computers.
             -p         Specifies optional password for user name. If you omit this
                        you will be prompted to enter a hidden password.
             -s         Run the remote process in the System account.
             -u         Specifies optional user name for login to remote
                        computer.
             -v         Copy the specified file only if it has a higher version number
                        or is newer on than the one on the remote system.
             -w         Set the working directory of the process (relative to
                        remote computer).
             -x         Display the UI on the Winlogon secure desktop (local system
                        only).
             -priority   Specifies -low, -belownormal, -abovenormal, -high or
                        -realtime to run the process at a different priority. Use
                        -background to run at low memory and I/O priority on Vista.
             computer   Direct PsExec to run the application on the remote
                        computer or computers specified. If you omit the computer
                        name PsExec runs the application on the local system,
                        and if you specify a wildcard (\\*), PsExec runs the
                        command on all computers in the current domain.
             @file      PsExec will execute the command on each of the computers listed
                        in the file.
             program    Name of application to execute.
             arguments  Arguments to pass (note that file paths must be
                        absolute paths on the target system).

        You can enclose applications that have spaces in their name with
        quotation marks e.g. psexec \\marklap "c:\long name app.exe".
        Input is only passed to the remote system when you press the enter
        key, and typing Ctrl-C terminates the remote process.

        If you omit a user name the process will run in the context of your
        account on the remote system, but will not have access to network
        resources (because it is impersonating). Specify a valid user name
        in the Domain\User syntax if the remote process requires access
        to network resources or to run in a different account. Note that
        the password is transmitted in clear text to the remote system.

        Error codes returned by PsExec are specific to the applications you
        execute, not PsExec.


        lol, No this has nothing to do with my other project. I supposed I could add it later, but for now I'm doing them as and when.

        cheers again.

        Blastman, you are the man. Thank You Very Much!!!!!!!!!



        blastman

          Topic Starter


          Hopeful

          Re: vbscript shell.run help....
          « Reply #5 on: June 06, 2008, 07:44:53 AM »
          sorted.

          I changed the start psexec line in my batch file and removed the /b switch. (which starts psexec in the same window.)

          anyway.

          Cheers for your help, yet again sidewinder!!

          legend!  ;D

          Blastman, you are the man. Thank You Very Much!!!!!!!!!