Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateProcessWithLogonW example

Status
Not open for further replies.

lsugirl

Programmer
May 24, 2004
24
US
Does anyone have a good CreateProcessWithLogonW example for registering a dll as an admin a machine? I am not a FoxPro programmer.

here is what I have so far but I'm getting a type mismatch error on the "CreateProcessWithLogonW" call.

*******************
*******************
#define LOGON_WITH_PROFILE 0x1
#define CREATE_NEW_PROCESS_GROUP 0x200

Declare Integer CreateProcessWithLogonW in advapi32.dll ;
String lpUsername , ;
String lpDomain , ;
String lpPassword , ;
Integer dwLogonFlags , ;
String lpApplicationName , ;
String lpCommandLine , ;
Integer dwCreationFlags , ;
Integer lpEnvironment , ;
String lpCurrentDirectory , ;
String @lpStartupInfo , ;
String @lpProcessInfo

Declare Long CloseHande in kernel32.dll ;
hObject as Long

cUser = "autoproxy"
cDomain = "corp"
cPass = "autproxy"
cAppName = "cmd.exe"
cCommandLine = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\REGASM.EXE " +lcProgramDestWebDLLQuotes + " /tlb /codebase /s"
cDir = lcProcessDir
pStart = long2str(68) + REPLICATE(CHR(0), 64)
pProc = REPLICATE(CHR(0), 16)

CreateProcessWithLogonW( ;
cUser , ;
cDomain , ;
cPass , ;
LOGON_WITH_PROFILE , ;
cAppName , ;
cCommandLine , ;
CREATE_NEW_PROCESS_GROUP , ;
null , ;
cDir , ;
@pStart , ;
@pProc ;


RETURN

********************
FUNCTION long2str
********************
* Passed : 32-bit non-negative numeric value (m.longval)
* Returns : ASCII character representation of passed
* value in low-high format (m.retstr)
* Example :
* m.long = 999999
* m.longstr = long2str(m.long)

PARAMETERS m.longval

PRIVATE i, m.retstr

m.retstr = ""
FOR i = 24 TO 0 STEP -8
m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
m.longval = MOD(m.longval, (2^i))
NEXT
RETURN m.retstr
*******************
*******************

Thanks in advance.


 
Can you please post an example of the return value you expect from long2str.
If you pass 999999, what is the return value suppose to be?


Walid Magd
Engwam@Hotmail.com
 
I would guess that it would be better not to use CMD.exe as a shell; ie:
Code:
   cAppName = "cmd.exe"
   cCommandLine = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\REGASM.EXE " +lcProgramDestWebDLLQuotes + "  /tlb /codebase /s"

becomes
Code:
   cAppName = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\REGASM.EXE"
   cCommandLine = lcProgramDestWebDLLQuotes + "  /tlb /codebase /s"


I would pass a 0 for the environment, and change its type to LONG (I don't know what VFP hands an API when giving it ".NULL.")... plus, nulls are ".NULL." .. not "null"

 
Thanks. I don't get the error anymore and it seems to run fine but the dll isn't getting registered.
 
I'm getting an error in the Event Log under Security. I don't make much sense since I'm not using Chinese.

Logon Failure:
Reason: Unknown user name or bad password
User Name: ????
Domain: ???
Logon Type: 2
Logon Process: Advapi
Authentication Package: Negotiate
Workstation Name: DEV3

 
I made some changes. I don't get the error in the Event Viewer anymore but the dll still isn't getting registered. I can take the command line and run it from a cmd window and it works.

CreateProcessWithLogonW( ;
cUser , ;
cDomain , ;
cPass , ;
LOGON_NETCREDENTIALS_ONLY , ;
cAppName , ;
cCommandLine , ;
CREATE_NEW_PROCESS_GROUP , ;
0, ;
cDir , ;
@pStart , ;
@pProc ;

I also changed the command line and exec lines.
cAppName = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\REGASM.EXE "
cCommandLine = cAppName + lcProgramDestWebDLLQuotes
 
for Walid:

********************
FUNCTION long2str
********************
* Passed : 32-bit non-negative numeric value (m.longval)
* Returns : ASCII character representation of passed
* value in low-high format (m.retstr)
* Example :
* m.long = 999999
* m.longstr = long2str(m.long)

PARAMETERS m.longval

PRIVATE i, m.retstr

m.retstr = ""
FOR i = 24 TO 0 STEP -8
m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
m.longval = MOD(m.longval, (2^i))
NEXT
RETURN m.retstr

 
I have made some changes. The CreateProcessWithLogonW functions returns a zero (fails) but when I run GetLastError, it thinks it ran success. The dll still isn't registered. ANY ideas??? Thanks in advance.

***************

#DEFINE FORMAT_MESSAGE_FROM_SYSTEM 0x00001000 && Value for use with FormatMessage API. From WINBASE.H
#DEFINE CR CHR(13) && Carriage Return
#DEFINE ERROR_SUCCESS 0 && Success error code from WINERROR.H
*!* #DEFINES from HOME()+"FOXPRO.h"
#DEFINE MB_ICONINFORMATION 64 && Information message
#DEFINE MB_OK 0 && OK button only

DECLARE INTEGER GetLastError IN kernel32.dll

DECLARE INTEGER FormatMessage IN kernel32.DLL ;
INTEGER dwFlags, ;
STRING @lpSource, ;
INTEGER dwMessageId, ;
INTEGER dwLanguageId, ;
STRING @lpBuffer, ;
INTEGER nSize, ;
INTEGER Arguments


lcResult = CreateProcessWithLogonW( ;
cUser , ;
cDomain , ;
cPass , ;
LOGON_NETCREDENTIALS_ONLY , ;
cAppName , ;
cCommandLine , ;
CREATE_NEW_PROCESS_GROUP , ;
0, ;
cDir , ;
@pStart , ;
@pProc ;
)

IF lcResult =0 THEN
lpBuffer = SPACE(128)
lnError = GetLastError()
=FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ;
'WINERROR.H', lnError, 0, @lpBuffer, 128 , 0)

=MESSAGEBOX("System error has occurred." + CR + ;
"System Error code: " + ALLTRIM(STR(lnError)) + CR + ;
"System Error message: "+ALLT(lpBuffer),MB_ICONINFORMATION+MB_OK,"ERROR")
ENDIF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top