Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Programming and problems on startup and Login

Posted on 2013-01-05
4
Medium Priority
?
355 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 22

Assisted Solution

by:mcsween
mcsween earned 1336 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 664 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 22

Accepted Solution

by:
mcsween earned 1336 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

877 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