WindowsProcessMBS CreateProcessWithLogonW

"Scott Carpenter" <[email protected]> Wed, 19 Dec 2018 10:58:55 -0500
Newsgroups gmane.comp.lang.realbasic.user
Message-ID <[email protected]>
------=_NextPart_000_0006_01D49789.D6283520
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

I am trying to launch an application from within a Xojo app using =
WindowsProcessMBS (code below). It is important that I use this function =
as it calls the Windows CreateProcessWithLogonW and I need to =
authenticate as this is being developed as a Windows service.

In testing with a console app all works well if I don=E2=80=99t try to =
authenticate, but when I include credentials, the LastErrorMessage =
returns "The parameter is incorrect".

I have reviewed the Microsoft documentation for CreateProcessWithLogonW:

=20

https://docs.microsoft.com/de-de/windows/desktop/api/winbase/nf-winbase-c=
reateprocesswithlogonw

=20

and tried leaving the domain null and passing the username in UPN format =
(user@domain). I have also tried entering the domain and username =
separately. I still get the parameter error.

Has anyone successfully used this function and any sample code to share?

=20

Code:

  dim w as new WindowsProcessMBS

  dim a as Integer

  dim AppPathStr, AppName as string

 =20

  AppPathStr=3D"C:\Windows\system32"

  AppName=3D"Notepad.exe"

 =20

  w.domain=3D"domain"

  w.UserName=3D"user"

  w.Password=3D"password" =20

  w.CurrentDirectory=3DAppPathStr

  w.ApplicationName =3D AppPathStr + "\" + AppName

 =20

  if not w.run then

    print "Launch Error: "+w.LastErrorMessage

    Return

  end if

=20

--

Scott Carpenter

=20

=20

=20

=20

=20


------=_NextPart_000_0006_01D49789.D6283520
Content-Type: text/html;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta =
name=3DGenerator content=3D"Microsoft Word 15 (filtered =
medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
	{mso-style-priority:99;
	mso-style-link:"Plain Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
pre
	{mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
	{mso-style-name:msonormal;
	mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
span.apple-style-span
	{mso-style-name:apple-style-span;}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted";
	font-family:Consolas;}
span.EmailStyle21
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;}
span.PlainTextChar
	{mso-style-name:"Plain Text Char";
	mso-style-priority:99;
	mso-style-link:"Plain Text";
	font-family:"Calibri",sans-serif;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal>I am =
trying to launch an application from within a Xojo app using =
WindowsProcessMBS (code below). It is important that I use this function =
as it calls the Windows CreateProcessWithLogonW and I need to =
authenticate as this is being developed as a Windows =
service.<o:p></o:p></p><p class=3DMsoNormal>In testing with a console =
app all works well if I don=E2=80=99t try to authenticate, but when I =
include credentials, the LastErrorMessage returns &quot;The parameter is =
incorrect&quot;.<o:p></o:p></p><p class=3DMsoNormal>I have reviewed the =
Microsoft documentation for CreateProcessWithLogonW:<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal><a =
href=3D"https://docs.microsoft.com/de-de/windows/desktop/api/winbase/nf-w=
inbase-createprocesswithlogonw">https://docs.microsoft.com/de-de/windows/=
desktop/api/winbase/nf-winbase-createprocesswithlogonw</a><o:p></o:p></p>=
<p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>and tried =
leaving the domain null and passing the username in UPN format =
(user@domain). I have also tried entering the domain and username =
separately. I still get the parameter error.<o:p></o:p></p><p =
class=3DMsoNormal>Has anyone successfully used this function and any =
sample code to share?<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal>Code:<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0 dim =
w as new WindowsProcessMBS<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0 =
dim a as Integer<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0 dim =
AppPathStr, AppName as string<o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0 <o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0=C2=A0AppPathStr=3D&quot;C:\Windows\system32&q=
uot;<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0 =
AppName=3D&quot;Notepad.exe&quot;<o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0 <o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0=C2=A0w.domain=3D&quot;domain&quot;<o:p></o:p>=
</p><p class=3DMsoPlainText>=C2=A0 =
w.UserName=3D&quot;user&quot;<o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0 w.Password=3D&quot;password&quot;=C2=A0 =
<o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0=C2=A0w.CurrentDirectory=3DAppPathStr<o:p></o:=
p></p><p class=3DMsoPlainText>=C2=A0 w.ApplicationName =3D AppPathStr + =
&quot;\&quot; + AppName<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0 =
<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0=C2=A0if not w.run =
then<o:p></o:p></p><p class=3DMsoPlainText>=C2=A0=C2=A0=C2=A0 print =
&quot;Launch Error: &quot;+w.LastErrorMessage<o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0=C2=A0=C2=A0 Return<o:p></o:p></p><p =
class=3DMsoPlainText>=C2=A0 end if<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal>--<o:p></o:p></p><p class=3DMsoNormal>Scott =
Carpenter<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p></div></body></html>
------=_NextPart_000_0006_01D49789.D6283520--