Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Programming and problems on startup and Login

Posted on 2013-01-05
4
Medium Priority
?
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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ā€¦
Progress
Suggested Courses

722 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