locked
CreateProcessAsUser returns error code 126 RRS feed

  • Question

  • Hi!

      I am new to visual c#.

     I tried to run a batch file using CreateProcessAsUser. It worked in my desktop(OS: Windows xp Service pack 3).In my laptop(OS: Windows xp Service pack 3) , It returns the error code 126.

    I dont understand, the error code what trying to say? please help me.

    Thanks in advance.

    Saravanan

    Thursday, September 13, 2012 9:48 AM

Answers

  • Hi,

    so I understood that you simply try to start a new process without any special security thoughts in your back.

    The simple solution for that could be the use of the Process class. Why don't you use that?

    One thing I see: You are calling a bat file. That is not really an executable. When creating a new process I normaly use %COMSPEC% when I start a batch file (So I directly start the executable and do not use the shell to check what type of file it is and what application should be used...). Not sure if that would change anything. (%COMSPEC% is an environment variable that tells you where the cmd.exe is located! And you can use it with /C argument to start anything else e.g. %COMSPEC% /C D:\Test\Sample.bat)

    The ERROR_MOD_NOT_FOUND is something I only know from systems where a file is missing. So maybe you have a broken or misconfigured system? If the system is not configured correctly so that it tries to do something wrong with a bat file, the %COMSPEC% use would help.

    With kind regards,

    Konrad

    Thursday, September 13, 2012 11:09 AM

All replies

  • Hi,

    can you give more details? What did you try exactly? Can you show your code or can you create an example that demonstrates the problem if you cannot show the production code?

    And what your requirements that you try to use that function through PInvoke (I understood that you are using http://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx )

    With kind regards,

    Konrad

    Thursday, September 13, 2012 10:02 AM
  • Hi Konrad!

       Thanks for your reply.

    This is the Sample code for your perusal.

    var sa = new SECURITY_ATTRIBUTES();
       sa.Length = Marshal.SizeOf(sa);

    CreateProcessAsUser(null, null, "D:\Test\Sample.bat", ref sa, ref sa,  false, 0, IntPtr.Zero,              "D:\Test", ref si, ref pi );

    it always returns 126( ERROR_MOD_NOT_FOUND,The specified module could not be found).

    Please help me out. And also could you tell me ," What are the scenarios, in this error occurs"

    Thursday, September 13, 2012 10:33 AM
  • Hi,

    so I understood that you simply try to start a new process without any special security thoughts in your back.

    The simple solution for that could be the use of the Process class. Why don't you use that?

    One thing I see: You are calling a bat file. That is not really an executable. When creating a new process I normaly use %COMSPEC% when I start a batch file (So I directly start the executable and do not use the shell to check what type of file it is and what application should be used...). Not sure if that would change anything. (%COMSPEC% is an environment variable that tells you where the cmd.exe is located! And you can use it with /C argument to start anything else e.g. %COMSPEC% /C D:\Test\Sample.bat)

    The ERROR_MOD_NOT_FOUND is something I only know from systems where a file is missing. So maybe you have a broken or misconfigured system? If the system is not configured correctly so that it tries to do something wrong with a bat file, the %COMSPEC% use would help.

    With kind regards,

    Konrad

    Thursday, September 13, 2012 11:09 AM
  • Hi konard,

        Thanks for your valuable reply.  I solved my problem by %COMSPEC%.

    The problem was ,"I ran a java program in bat file. But JAVA_HOME variable not initialized. When ran the bat file using %COMSPEC%, its denoted me.

    Tuesday, September 18, 2012 6:34 AM