Thursday, July 05, 2012

How to 'Run As' multiple programs using a script in windows

As a system engineer or as a developer sometimes you may need to run multiple programs at once as a sequence or, one by one after some intervals. Following is a VB script created for specific purpose.

  • weAdmin\imAdmin - Specific use for "Run As"
  • C:\Test\Test1\Test1.exe - Path and file name
  • admin1234 - Password for the specific user.
  • 100 - Some waiting time to initialize 'run as'
  • 1000 - waiting time until next program run. (Configure this as you want)
Option explicit
Dim oShell
set oShell= Wscript.CreateObject("WScript.Shell")

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test1\Test1.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234" 
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test2\Test2.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234"
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test3\Test3.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234"
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

oShell.Run "RunAs /noprofile /user:weAdmin\imAdmin ""C:\Test\Test4\Test4.exe"""
WScript.Sleep 100
oShell.Sendkeys "admin1234"
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000

Wscript.Quit

"The application has failed to start because the side by side configuration is incorrect please see the application event log or use the command line sxstrace.exe tool for more detail"

After finished the developmental of the application you may move the binaries to the separate windows 2008 serve and try to run. So at the time you may face to a error message box that show the above error message or some error near to that. If that now be ready to correct it.


Error Message

SETP : 01

1. Click on the Start button
2. Go to control panel
3. Change "View by"(located at right side top op the control panel) to "Large icons"
4. Click on Program and Features.



STEP 02:

01. On the "Program and Features" window  click on the "Turn windows features on or off"



02. Then click on the "Features"

03. Check weather ".NET Frameworks 3.5.1 Features" checked  or not if not check it



04.  Click "Next" and click on the "Add required Role Services"


05. Click Install



06. Click next and next and next and wait wait until installation finished


07. Click next and close



08. Then close everything
09. Right click the "My Computer" > Go the "Manage" > Go to "Event Viewer".
10. Then go to "Windows Logs" > Go to "Applications"


So you will see this side of side to side errors. If not please try to run your application or program again and then check.


11. Right click on the error and go to "Event Properties"



12. You read the error message and check the "Processor architecture". In this case it is "X86" means 32 bit.

13. The Check the VC++ version you use to code the application. it may be VS 2005, 2008 or 2010.

14. So then combine your server computer architecture and developed computer VC++ version and download the C++ re-distributable package. Then install it in the server.

As examples

Processor Architecture
VC++ version
C++ Redistributable Pacakge
X86
VC++ 2005
Microsoft Visual C++ 2005 SP1 Redistributable Package (x86) 
X86
VC++ 2008
Microsoft Visual C++ 2008 SP1 Redistributable Package (x86) 
X64
VC++ 2010
Microsoft Visual C++ 2010  Redistributable Package (x64) 
X64
VC++ 2005
Microsoft Visual C++ 2008 SP1 Redistributable Package (x64) 

15. Restart the server and run your program again

16. If not success you have to Diagnosing SideBySide failures using sxstrace.exe. For more details about this
go to this link.
http://blogs.msdn.com/b/junfeng/archive/2006/04/14/576314.aspx