We help IT Professionals succeed at work.

I need help to tell me what end statement I need to keep this routine from erroring out.

Splunker
Splunker asked
on
242 Views
Last Modified: 2011-09-20
I got this script to run another script from login. I tried testing it and it came back with an error when the person logged in. The errors was something like missing an end statement. I dont know VB. I pasted only whats below into a text file and then changed the ext to .vbs and put it into my login script. I do have another vb script names RunasSample.vbs which I assume this statement is trying to execute it.  Do I need a "end" at  the end of this script or something like "wscript.quit"  Keep in mind I did fill in the server name, sharename  and directories to where the other vb script is located.

or is this statement needing alot more coding?

Thanks
Jeff

'*********************************************************************
' Sample statements to call from the login script
      
Dim g_OShell
Set g_OShell = CreateObject ("Wscript.Shell")                                                    
g_OShell.Run WScript.FullName & " \\ServerName\ShareName\Directory1\Directory2\RunAsSample.vbs", 0, False
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
The error you are talkign about can't come from this script. It must be coming from RunAsSample.vbs Post that.

Author

Commented:


Okay here it is below
******************************

Option Explicit

On Error Resume Next

Dim WshShell
Dim WshNetwork
Dim WshEnv
Dim fso
Dim WinPath
Dim RunAsFlag
Dim sUser
Dim sPass
Dim ProgramName
Dim Command  
Dim CommandFile

Const ForReading = 1, ForWriting = 2, ForAppend = 8

Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("Process")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
WinPath = WshEnv("SystemRoot")&"\System32\runas.exe"
RunAsFlag = True

If Not fso.FileExists(WinPath) Then
      Set CommandFile = fso.OpenTextFile ("C:\" & WshNetwork.ComputerName & ".Command.txt", ForAppend, True)
      CommandFile.WriteLine Now() & ": Can't find or verify " & WinPath & "." & VBCRLF & "You must be running Windows 2000 or higher for this script to work."
      CommandFile.Close
      RunAsFlag = False
End If



'************************** Enter Information Here ****************

' This is the user name and password of the account that is the local administrator of the workstation
sUser = "domain\username"
sPass = "password" & VBCrLf

' Enter the location of the file to be installed.  Must be a UNC location as drive
'  letters will not work.  Multiple ProcessFile lines may be included.

ProcessFile "\\servername\directory\directory\filename.exe"
ProcessFile "\\servername\directory\directory\filename.exe"

'**************************

EndScript

'*****************************************

Sub ProcessFile (ProgramName)

      On Error Resume Next

      Dim Return
      Dim InstallLogName
      Dim A
      Dim ProgramLocation
      Dim CurrentVersion

      Err.Clear

      If Not fso.FileExists(ProgramName) Then
          Set CommandFile = fso.OpenTextFile ("C:\" & WshNetwork.ComputerName & ".Command.txt", ForAppend, True)
          CommandFile.WriteLine Now() & ProgramName & " does not exist"
          CommandFile.Close
            Exit Sub
      End If

      InstallLogName = UCase(ProgramName) & ".LOG"
      A = InStrRev(InstallLogName, "\")
      If A > 0 Then
            InstallLogName = Right(InstallLogName, Len(InstallLogName) - A)
      End If
      InstallLogName = "C:\" & WshNetwork.ComputerName & "." & Trim(InstallLogName)
        
      fso.DeleteFile InstallLogName, True
      Err.Clear

      
      Set CommandFile = fso.OpenTextFile ("C:\" & WshNetwork.ComputerName & ".Command.txt", ForAppend, True)
      If RunAsFlag = True Then
          Command = "CMD /c runas.exe /noprofile /user:" & sUser & " " & Chr(34) & ProgramName & " /s /v/qn\" & Chr(34) & " /l*v \" & Chr(34) & InstallLogName & "\" & Chr(34) & Chr(34) & Chr(34)
      Else
        Command = Chr(34) & ProgramName & Chr(34) & " /s /v/qn" & Chr(34) & " /l*v \" & Chr(34) & InstallLogName & Chr(34) & Chr(34)
      End If
                                                                    
      CommandFile.WriteLine Now() & ": " & Command
      CommandFile.Close
      
    return = WshShell.Run (Command, 1, False)
      
    If RunAsFlag = True Then
          WScript.Sleep 30 'need to give time for window to open.
          WshShell.AppActivate (WinPath) 'make sure we grab the right window to send password to
          WshShell.SendKeys sPass 'send the password to the waiting window.
      End If
      
      WScript.Sleep 30000

End Sub


Sub EndScript

    Set WshShell = Nothing
    Set WshEnv = Nothing
    Set fso = Nothing
    Set WshNetwork = Nothing

      WScript.Quit

End Sub

Author

Commented:
It also has this stuff below at the very top.
******************************


'<% RunAsSample.VBS
'
' *********************************************************************************
' * THIS PROGRAM IS OFFERED AS IS AND MAY BE FREELY MODIFIED OR ALTERED AS *
' * NECESSARY TO MEET YOUR NEEDS. THE AUTHOR MAKES NO GUARANTEES OR WARRANTIES, *
' * EXPRESS, IMPLIED OR OF ANY OTHER KIND TO THIS CODE OR ANY USER MODIFICATIONS. *
' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB *
' * ENVIRONMENT. USE AT YOUR OWN RISK. *
' *********************************************************************************


'******************************************************************************************************
'*      Sample statements to call from the login script                                                                                *
'*                                                                                                                                                        *
'*      Dim g_OShell                                                                                                                                *
'*      Set g_OShell = CreateObject ("Wscript.Shell")                                                     *
'*      g_OShell.Run WScript.FullName & " \\ServerName\ShareName\Directory1\Directory2\RunAsSample.vbs", 0, False    *
'******************************************************************************************************
CERTIFIED EXPERT
Top Expert 2006

Commented:
That also seems ok. Could you run that script directly? Like

C:\WINNT\system32\cscript.exe \\ServerName\ShareName\Directory1\Directory2\RunAsSample.vbs

Author

Commented:
Maybe I should give you the exact error first.. Maybe I am missing something. I will be right back with the exact error.

Author

Commented:

Below is the error.  RunAsITI.vbs is what I name the code for the
"Sample statement to call from Login script" The first code I posted this is why I thought it was an end statment issue.
************************************************
                                          Windows Script Host

Script: \user\scripts\logon\RunAsITI.vbs

Line: 1
Char: 36
Error:  Expected end of statement
code: 800A0401
Source: Microsoft compilation error.
CERTIFIED EXPERT
Top Expert 2006

Commented:
How are you running this script?

Author

Commented:
I do it using a group policy for the logon. I want this program to install when users login. This script was created by our vendor for software we use that needs to be upgraded on every workstation. This script is suppose eliminate us having to go to each workstation to install it. It logs in with administrative user and permissions and installs it for the user.
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
To be more exact. I right click on the OU that my user is in and go to properties select the group policy tab. Select new policy name it Premier upgrade. Edit the policy go to the user configuration in the Windows settings then scripts then logon. Open the logon select show files put the RunAsITI.vbs in there. Then I select Add for the Logon and pick the RunAs ITI.vbs.  then close out of it all. I have the user login and then I get this error.

Author

Commented:
Okay I found out what wrong. On The RunAsITI.vbs there was a one astrik in the code that I didnt see. It was way off on right side of the page I didnt see it because would have had to scroll over. when I pasted it into the post I deleted it and didnt realize it.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.