CreateProcessAsUser or LogonUser
-
How can I use the CreateProcessAsUser or LogonUser when staring the process:
Dim ps As New System.Diagnostics.Process
ps.StartInfo.UseShellExecute = False
ps.StartInfo.Domain = Domain
ps.StartInfo.UserName = UserNameDim pword As New System.Security.SecureString() For Each c As Char In Password pword.AppendChar(c) Next ps.StartInfo.Password = pword ps.StartInfo.LoadUserProfile = False 'This Works: ps.StartInfo.WorkingDirectory = ApplicationWorkingDir ps.StartInfo.FileName = "cmd.exe" 'Win2012 run as admin ps.StartInfo.Verb = "runas" If BatchSize = String.Empty Then ps.StartInfo.Arguments = "/c bcp " + DbTable + " in " + SourceFile + " -m " + MaxErrors + " -f " & FMTFile & " -e " & ErrorFile & " -o " & LogFile & " -S " & ServerName & " -T " Else ps.StartInfo.Arguments = "/c bcp " + DbTable + " in " + SourceFile + " -m " + MaxErrors + " -f " & FMTFile & " -b" & BatchSize & " -e " & ErrorFile & " -o " & LogFile & " -S " & ServerName & " -T" End If ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden ps.Start() ps.WaitForExit()
To quote Dave: "On top of everything else, in order for the Hidden window option to work you have to change the UseShellExecute property to True." - in which case the verb won't work. Calling BCP from .net on Windows 2012 - Visual Basic Discussion Boards - CodeProject[^]
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
To quote Dave: "On top of everything else, in order for the Hidden window option to work you have to change the UseShellExecute property to True." - in which case the verb won't work. Calling BCP from .net on Windows 2012 - Visual Basic Discussion Boards - CodeProject[^]
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
it's a console application running on a server from a scheduler. I need to start a process as specific user with access to cmd.exe and pass userID in my process
byka wrote:
it's a console application running on a server from a scheduler.
The default task scheduler[^] contains options to run your app under another account. So, I assume you are not using that task-scheduler?
byka wrote:
I need to start a process as specific user with access to cmd.exe and pass userID in my process
You mean that it should display a console-window where the user can execute additional commands? You don't need to start CMD just to execute an application that you would normally start using the CMD-prompt.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
byka wrote:
it's a console application running on a server from a scheduler.
The default task scheduler[^] contains options to run your app under another account. So, I assume you are not using that task-scheduler?
byka wrote:
I need to start a process as specific user with access to cmd.exe and pass userID in my process
You mean that it should display a console-window where the user can execute additional commands? You don't need to start CMD just to execute an application that you would normally start using the CMD-prompt.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
Maybe this explanation will help : scheduler running under user account with no permission to C: drive. Application account should have some permission to C:drive in order to access cmd.exe I need to add code ( CreateProcessAsUser or LogonUser) for application user in order to call cmd.exe
-
Maybe this explanation will help : scheduler running under user account with no permission to C: drive. Application account should have some permission to C:drive in order to access cmd.exe I need to add code ( CreateProcessAsUser or LogonUser) for application user in order to call cmd.exe
OK, this is a bit better but there's still lots of detail missing. You're writing the scheduler app? Is this written as a standard console or Windows Forms application or is it a service? Does the application this scheduler is launching have to show up as a window that the user can type in? Why must you call CMD instead of just launching BCP directly?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Maybe this explanation will help : scheduler running under user account with no permission to C: drive. Application account should have some permission to C:drive in order to access cmd.exe I need to add code ( CreateProcessAsUser or LogonUser) for application user in order to call cmd.exe
byka wrote:
Maybe this explanation will help
An answer to the question would have helped too. Are you or are you not using the default task scheduler? If yes, simply define the account you want to run under in the settings.
byka wrote:
scheduler running under user account with no permission to C: drive. Application account should have some permission to C:drive in order to access cmd.exe
..sounds safer to give the user the permissions he/she actually needs. The user you are impersonating prolly has some more priviliges than just "cmd.exe".
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
Maybe this explanation will help : scheduler running under user account with no permission to C: drive. Application account should have some permission to C:drive in order to access cmd.exe I need to add code ( CreateProcessAsUser or LogonUser) for application user in order to call cmd.exe
If you're using the default task scheduler, supply credentials that have appropriate permissions. If you've baked your own task scheduler, run it as a service, using credentials that have appropriate permissions. Either way, the wheel, axle, transmission, and engine have already been invented. You just need to paint the car.
-
OK, this is a bit better but there's still lots of detail missing. You're writing the scheduler app? Is this written as a standard console or Windows Forms application or is it a service? Does the application this scheduler is launching have to show up as a window that the user can type in? Why must you call CMD instead of just launching BCP directly?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakYou're writing the scheduler app? - Yes Is this written as a standard console or Windows Forms application or is it a service? - Consolse application Does the application this scheduler is launching have to show up as a window that the user can type in? - No Why must you call CMD instead of just launching BCP directly?- you mean call bcp.exe instead of cmd?
-
You're writing the scheduler app? - Yes Is this written as a standard console or Windows Forms application or is it a service? - Consolse application Does the application this scheduler is launching have to show up as a window that the user can type in? - No Why must you call CMD instead of just launching BCP directly?- you mean call bcp.exe instead of cmd?
byka wrote:
you mean call bcp.exe instead of cmd?
Yes
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
byka wrote:
you mean call bcp.exe instead of cmd?
Yes
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
That's not an answer to the question. WHY do you think you must call CMD instead of just launching BCP directly?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
What kind of app are you writing and where is this process being started? Is this a Windows Forms app, console app, WPF, Windows Service, ASP.NET, ... ?? Is the process being created locally, meaning on the same machine as the code you've shown or is it being created on a remote machine? ....and you STILL do not have to run CMD and do not need the "RunAs" verb line. It's nice to see you don't listen to the answers you've been given.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakDreams tailoring house custom make clothes for your body type, to suit unique shape size- experience pleasure of the fit you have always dream of!
you’re into on-trend suit designs that don’t have to huge pricetag, then dreams tailoring house is a great option.If you’re feeling really sassy,
get yourself into one of the dreams tailoring house suits. You’ll never look back.If you are a more reserved gentleman who only wants the best, then I recommend dreams tailoring house.
we are specialized in school uniforms, college uniforms, nursing uniforms,hospital uniforms,coat suits…etc.
<a href=http://www.kovaisuperoffer.com/ad/dreams-tailoring-house-tailoring-in-sundrapuram//</a>