VB Programming and problems on startup and Login

Hi,

I have a system that copies files depending on whether the vpn connection is up or  not, and when the machine starts i run the following script (manually) which runs other scripts and batch files in the directory and they all run fine. (its called run.vbs)

On Error Resume Next
dim WshShell

set WshShell = CreateObject("WScript.Shell")


WshShell.Run "wscript.exe UTVCopyfilesfromserver.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe irnCopyfilesfromservertext.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe utvnewsaudioconversion.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe irnnewsaudioconversion.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe UTVscriptexttonews.vbs", 2, FALSE
WScript.sleep 3000
WshShell.Run "wscript.exe irnscriptexttonews.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe irnCopyfilesfromserveraudio.vbs", 2, FALSE
WScript.Sleep 3000

WshShell.Run "cmd.exe /c copytoirnboxirntxt.bat", 2, FALSE
WshShell.Run "cmd.exe /c copytoirnboxutvaudio.bat", 2, FALSE
WshShell.Run "cmd.exe /c copytoirnboxutvtext.bat", 2, FALSE
WshShell.Run "cmd.exe /c irnaudiorobocopy.bat", 2, FALSE


But if the vpn connection goes down the machine restarts and i then i have a batch file that runs the run.vbs file and its called runf.bat and this is it

cd /D "%~dp0"
cscript run.vbs %*

But whenever the batch file runs on login (windows logs in automatically) the run.vbs runs but the scripts inside don't seem to run properly

Is there a program or something i can do to make sure they all run fine when machine restarts unattended.

also the reason i have it running as a batch file is because i can then tell that the scripts are running by being able to see the black boxes
jonathanduane2010Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mcsweenConnect With a Mentor Sr. Network AdministratorCommented:
They should be able to tell remotely the same as locally if you are forcing CScript.  You could always just put a msgbox in there to tell the user the script ran.  Just add this to the last line of the script.
msgbox "Script Ran Successfully",vbOk

Open in new window

0
 
mcsweenConnect With a Mentor Sr. Network AdministratorCommented:
To force CScript from within the VBS add this to the end of your script.
Sub forceUseCScript()
   If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
      wShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34),1,False
      WScript.Quit 0
   End If
End Sub

Open in new window

And put this as the very first line
forceUseCScript

Open in new window

If you aren't already I would set these scripts to run in group policy.  I assume this system is not part of Active Directory so you can set it in the local policy.

Start, Run, gpedit.msc
If you want it to run when logging in go to User Configuration, if you want it to run when the computer is starting go to Computer Configuration
Windows Settings
Scripts Logon/Logoff (or Startup/Shutdown if in computer node)

You can also copy files using vbscript (so you don't have to call batch files) using the following code.  The True at the end means overwrite.
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "\\someserver\someshare\somefile.txt","C:\Somelocalfolder\",True

Open in new window

0
 
jonathanduane2010Author Commented:
If i put it into user config within a group policy then if someone remotely connects to the machine they wont be able to tell if the scripts are running or not isnt that correct?

and if so is there anyway of telling if they will?
0
 
shorvathConnect With a Mentor Commented:
jonathanduane2010,

I've been there with trying to do scripts to copy files, and all the problems associated with that method until I discovered a FREE utility from Microsoft (unsupported) called RichCopy.

http://technet.microsoft.com/en-us/magazine/2009.04.utilityspotlight.aspx

I've been using it for years and it works flawlessly.  You can schedule jobs at start-up, or to run periodically, and it allows for a log files so you can view the status of jobs.  It might be a bit of work to set up all of your jobs (easier than Robocopy because it has a nice GUI) but once your done, it's worth it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.