Clicky

I have a .vbs set to run in my login script...I use this script to update a program on all of the users computers. My question is, is there a way I can edit the vb code so it will only run one time & not each time the user logs into the domain?
 set oShell= Wscript.CreateObject("WScript.Shell")   oShell.Run "runas /user:mydomain\administrator ""\\server\path\addin.bat""", 2 WScript.Sleep 500   oShell.Popup "Please wait while the installation begins.....",2,"Technology Team",0+64   oShell.Sendkeys "mypassword"  oShell.Sendkeys "~"  Wscript.Quit                             
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 

Select allOpen in new window

asked 12/15/2011 03:09

wantabe2's gravatar image

wantabe2 ♦♦


5 Answers:
Here you go! Make this script your login script. Change asoftware lines.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
Const ForReading = 1, ForWriting = 2
   newFile = 0
   Dim aSoftware(0, 2)
   aSoftware(0,0) = "Name of Script"
   aSoftware(0,1) = "Path to Script on Server"
   aSoftware(0,2) = "Fake Path to Fake File. Used when you want to run two scripts"
      
   On Error Resume Next
   Set WshShell = CreateObject("WScript.Shell")
   Set fso = CreateObject("Scripting.FileSystemObject")
   If fso.FileExists("C:IS.dat") = 0 Then    'If file is present, read contents to determine installed software
     Set fDataFile = fso.CreateTextFile("C:IS.dat", True)
     fDataFile.close
     set f = fso.GetFile("C:IS.dat")
     f.attributes = 6
     newFile = 1
   End If
   Set fDataFile = fso.OpenTextFile("C:IS.dat", ForReading)
   Do While Not fDataFile.AtEndOfStream
     strSoftware = fDataFile.ReadLine
   Loop
   fDataFile.close
   aLoadedSoftware = Split(strSoftware, ",", -1, 1)
   For o = 0 To UBound(aSoftware)
     found = 0
     For i = 0 to UBound(aLoadedSoftware)
       If aSoftware(o, 0) = aLoadedSoftware(i) Then
         found = 1
         i = UBound(aLoadedSoftware)
       End If
     Next
     If found = 0 Then
       If newFile = 1 Then
         strSoftware = aSoftware(o, 0)
         newFile = 0
       Else
         strSoftware = strSoftware & "," & aSoftware(o, 0)
       End If
       set f = fso.GetFile("C:IS.dat")
       f.attributes = 0
       Set fDataFile = fso.OpenTextFile("C:IS.dat", ForWriting, True)
       fDataFile.writeLine strSoftware
       fDataFile.close
       f.attributes = 6
       If Not IsEmpty(aSoftware(o, 1)) And aSoftware(o, 1) <> "" Then
         Set oExec = WshShell.Exec(aSoftware(o, 1))
         Do While oExec.Status = 0
           WScript.Sleep 100
         Loop
       End If
       If Not IsEmpty(aSoftware(o, 2)) And aSoftware(o, 2) <> "" Then
         Set oShell = WScript.CreateObject ("WSCript.shell")
         oShell.run aSoftware(o, 2), 0, true
         Set oShell = Nothing
       End If
     End If
   Next
link

answered

Jmoody10's gravatar image

Jmoody10

What do I need to add to that code to make the .bat file called on line 5 to run as administrator?
link

answered 2011-12-15 at 11:12:50

wantabe2's gravatar image

wantabe2

Depending on what your BAT file actually does, couldn't you check something on the computer that is logging in to determine if the script has already been run or not?

~bp
link

answered 2011-12-15 at 11:17:20

billprew's gravatar image

billprew

Make it a startup script.
link

answered 2011-12-15 at 11:42:12

Jmoody10's gravatar image

Jmoody10

If you're running an installation, I generally check for an EXE installed by the program, and check it's file version to determine whether the install needs to run or not...
link

answered 2011-12-15 at 12:30:03

RobSampson's gravatar image

RobSampson

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×33

Asked: 12/15/2011 03:09

Seen: 258 times

Last updated: 12/15/2011 06:42