happyhippo
31st January 2011 15:45 UTC
RunAs error: The stub received bad data.
Hi there,
I am using the following expression to start an update program that requires admin rights:
SetOutPath "$EXEDIR"
File "RunAsDll\RunAs.dll"
StrCpy $1 "$ADMIN_LOGON"
StrCpy $2 "$ADMIN_PASSWD"
StrCpy $3 "$INST_TEMP\${UPDATE_FILE}"
StrCpy $4 0
System::Call 'RunAs::RunAsW(w r1,w r2,w r3,*w .r4) i .r0 ? u'
DetailPrint "RunAs Message: $4 ($0)"
If I run this script I receive the following error through the $4 variable: “The stub received bad data.” and the $0 variable shows the value 0.
The script runs on RequestExecutionLevel user (if this makes any difference).
I have double checked all of the variables $1-$3 but they are all correct. I also have searched the internet for this error but did not find anything that helped further.
So does anybody know what this error means and how to resolve it?
Many Thanks.
Anders
31st January 2011 18:53 UTC
RPC_NT_BAD_STUB_DATA=The stub received bad data
I can't tell you why it is failing, but I can tell you that this plugin has some bugs (leaks two kernel handles or the error string each time you call it) but that is not the reason why it fails.
On my XP box, it fails with "Access Denied" if the secondary logon service is not running, so the only suggestion I have is to make sure that service is running. If I start that service this code works for me:
outfile test.exe
requestexecutionlevel user
page instfiles
section
initpluginsdir
SetOutPath $pluginsdir
File "RunAs.dll"
>StrCpy $1 "xxxxxx"
>StrCpy $2 "xxxxxx"
>StrCpy $3 "$sysdir\calc.exe"
>System::Call 'RunAs::RunAsW(w r1,w r2,w r3,*w .r4) i .r0 ? u'
>SetOutPath $temp
messagebox mb_ok "RunAs Message: $4 ($0)"
>sectionend
>
My other suggestion would be to run Process Monitor and see if it gives you any hints (Bad path, access denied etc)
happyhippo
1st February 2011 12:34 UTC
The secondary logon service is running.
I have also tested your test script and faced the same problem.
Then I have used the Process Monitor to watch the process but did not find any obstacles (but this may be due to my limited knowledge in that area). I have attached the Process Monitor recording, may be one of you can recognise any problem.
My test script looks like the following:
outfile test.exe
requestexecutionlevel user
page instfiles
Section
initpluginsdir
SetOutPath $pluginsdir
File "RunAsDll\RunAs.dll"
>StrCpy $1 "xxx"
>StrCpy $2 "yyy"
>StrCpy $3 "C:\WINDOWS\NOTEPAD.EXE"
>MessageBox MB_OK "1:$1 2:$2 3:$3 4:$4"
>System::Call 'RunAs::RunAsW(w r1,w r2,w r3,*w .r4) i .r0 ? u'
>MessageBox MB_OK "RunAs Message: $4 ($0)"
>SetOutPath $temp
SectionEnd
>
The Process Monitor recording was done between the first and the second message box.
happyhippo
18th February 2011 08:05 UTC
I have tested it with another machine and recognised that it worked before some patches have been applied, but after the wsus installed some XP and Office updates the error occured. Unfortunatly I was not able to identify the patch, which causes the problem.
Anyhow, part of the RunAs plugin does anybody know another method with NSIS to call a process with another user? Is there maybe a system call that I could use?
Anders
18th February 2011 12:48 UTC
You could call CreateProcessAsUser/CreateProcessWithLogon etc with the system plugin...
Afrow UK
18th February 2011 14:50 UTC
I wrote this plug-in quite a while ago: http://nsis.sourceforge.net/File:RunAs.zip
Stu
happyhippo
18th February 2011 15:40 UTC
Thanks for the quick answer.
@ Afrow UK, I have used your plug-in under XP before, but unfortunatly it did not run under Windows 7.
@ Anders, I have looked at them as well, but as I am not a very good programmer I had some problems to find the right syntax.
However, I think I have found another solution. I am using a freeware tool called runasspc and starting it with an ExecWait command.
This is my new test script:
outfile test_runasspc.exe
requestexecutionlevel user
ShowInstDetails show
Page instfiles
Section
SetShellVarContext all
SetOutPath $APPDATANSIS_Temp
File "runasspc\runasspc.exe"
>File "7_admin.exe" ;the file performs the elevation for Windows 7 and some system changes
StrCpy$1 "AdminUser"
>StrCpy $2 "Password"
>StrCpy $3 "Domain"
>StrCpy $4 '"$APPDATA\NSIS_Temp\7_admin.exe"'
>SetDetailsPrint none ; in order to hide the password
ExecWait'"$APPDATA\NSIS_Temp\runasspc.exe" /user:$1 /password:$2 /domain:$3 /program:$4 /quiet' $0
SetDetailsPrint both
DetailPrint "Exec Message: $0"
>messagebox mb_ok "Exec Message: $0"
>SetOutPath $APPDATA
RMDir/r /REBOOTOK "$APPDATA\NSIS_Temp"
>SectionEnd
>