Question

I have a vb.net 2008 application that is supposed to run at startup. After meeting certain conditions, the PC is supposed to restart. Below is the code that is failing:

System.Diagnostics.Process.Start("shutdown", "-r -t 00 -f", myUsername, myPassword, myDomain)

myUsername and myDomain are both strings while myPassword is a SecureString. The application works properly when execute manually, but give the following error when executed from startup (either by placing in the startup folder or by adding to the registry):

The directory name is invalid

Also, the program executes properly when the last 3 arguments are left out and the user has the necessary rights.

How do I force a restart using an specific, alternate user credentials on startup?

Was it helpful?

Solution

You are starting the process with the current working directory as the default. That can cause problems if that directory isn't valid for the user you specify. Use the Process.Start(ProcessStartInfo) overload instead. Set the ProcessStartInfo.WorkingDirectory to a directory that's good for any user. Like c:\

More info in this KB article.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top