Solved

VB Programming and problems on startup and Login

Posted on 2013-01-05
4
347 Views
Last Modified: 2013-01-21
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
0
Comment
Question by:jonathanduane2010
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:mcsween
mcsween earned 334 total points
ID: 38747359
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
 

Author Comment

by:jonathanduane2010
ID: 38747439
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
 
LVL 9

Assisted Solution

by:shorvath
shorvath earned 166 total points
ID: 38750489
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
 
LVL 21

Accepted Solution

by:
mcsween earned 334 total points
ID: 38750784
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now