문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top