how to execute a script by certain windows or domain account?

B

Bishoy George

Hi All,

I tried to execute a certain vb script file by a windows application to run
the script with certain windows or domain account.

I tried to do that by
System.Diagnostics.Process.Start(fileName, userName, password, domain);

The problem is that I had the following exception: The specified executable
is not a valid Win32 application

Error Details:
-------------

System.ComponentModel.Win32Exception was unhandled
Message="The specified executable is not a valid Win32 application."
Source="System"
ErrorCode=-2147467259
NativeErrorCode=193
StackTrace:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName, String userName,
SecureString password, String domain)
at NetworkConfigCS.FormExecuteScript.btnRun_Click(Object sender,
EventArgs e) in E:\F\Work
Place\Applications\NetworkConfig\NetworkConfigCS\FormExecuteScript.cs:line
40
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at NetworkConfigCS.Program.Main() in E:\F\Work
Place\Applications\NetworkConfig\NetworkConfigCS\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
J

Jim Wooley

Hi All,
I tried to execute a certain vb script file by a windows application
to run the script with certain windows or domain account.

I tried to do that by
System.Diagnostics.Process.Start(fileName, userName, password,
domain);
The problem is that I had the following exception: The specified
executable is not a valid Win32 application

You don't just pass the script file as the filename. The script file is processed
by a script engine. In windows, the engine is cscript.exe. Thus to execute
a script file called MyScript.vbs, you would use "cscript.exe myscript.vbs".
Watch your pathing if you are executing this in directories other than the
current operating directory.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
S

Stoitcho Goutsev \(100\)

Jim,

Anything that can be typed in the command prompt can be started using
Process.Start. In other word if there is proper file extention association
between *.vbs and the script engine then providing the file name to the vbs
file should be just enough.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top