Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Error: Incorrect function when using Win32::AdminMisc::CreateProcessAsUser

by merlinX (Novice)
on Dec 22, 2010 at 10:37 UTC ( #878471=perlquestion: print w/replies, xml ) Need Help??
merlinX has asked for the wisdom of the Perl Monks concerning the following question:


Not sure if this is a bug or not but we hit this problem when using Win32::AdminMisc::CreateProcessAsUser:
Error: Incorrect function.

Maybe you can shed a light on what's wrong? (or on what we might be doing wrong?)
Please Help (!) Feedback greatly appreciated. Thank you for your time (!)

Version is:
Y:\xavier>perl -MWin32::AdminMisc -Iy:\xavier\perl\lib -le "print $Win32::AdminMisc::VERSION"

What we see on screen when executing is:
Enter Password:********
User(uuuuuu) Domain(dddddd) Password(********) Process (cmd)
Sucessfully logged on as uuuuuu .
Launching cmd...
Error: Incorrect function.

What I found already
When searching the Internet with
Win32::AdminMisc "Incorrect function"
I find an old 2003 entry describing this same error

Script contents here

use Win32; use Win32::AdminMisc; my (undef, $Domain, $User) = ( $ARGV[0] =~ /((.*?)\\)?(.*?)$/ ); my $Password = $ARGV[1]; if( '*' eq $Password){ print "Enter Password:"; $Password = <STDIN>; chop $Password; } my $Process = $ARGV[2]; ("" eq $Domain) ? $User: "$Domain\\$User"; print "User($User) Domain($Domain) Password($Password) Process($Proces +s)\n"; #exit 0; if(Win32::AdminMisc::LogonAsUser($Domain,$User,$Password,LOGON32_LOGON +_INTERACTIVE)){ my $LogonUser = Win32::AdminMisc::GetLogonName(); print "Sucessfully logged on as $LogonUser .\n"; print "\nLaunching $Process...\n"; my $Pid = Win32::AdminMisc::CreateProcessAsUser( $Process, "Flags", CREATE_NEW_CONSOLE, "XSize", 640, "YSize", 400, "X", 200, "Y", 175, "XBuffer", 80, "YBuffer", 175, "Title", "Title: $User" . "'s $Proc +ess program", "Fill", BACKGROUND_BLUE | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN, ); if($Pid){ print "Successfull! The new process PID is $Pid.\n"; } else{ print "Failed.\n\tError: ", Error(), "\n"; } } else{ my $err=Win32::FormatMessage( Win32::AdminMisc::GetError()); print "HERE $err\n"; } sub Error{ return Win32::FormatMessage( Win32::AdminMisc::GetError()); } exit 0;
  • Comment on Error: Incorrect function when using Win32::AdminMisc::CreateProcessAsUser
  • Download Code

Replies are listed 'Best First'.
Re: Error: Incorrect function when using Win32::AdminMisc::CreateProcessAsUser
by jfroebe (Parson) on Dec 22, 2010 at 15:19 UTC

    What version of Windows are you running this code on?

    Jason L. Froebe

    Blog, Tech Blog

      I tested this on a windows XP Win32::GetOSVersion() dump shows
      $VAR1 = [ 'Service Pack 3', 5, 1, 2600, 2, 3, 0, 256, 1 ];
      I tested this also on a windows 2003 Win32::GetOSVersion() dump shows
      $VAR1 = [ 'Service Pack 2', 5, 2, 3790, 2, 2, 0, 272, 3 ];

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://878471]
Approved by herveus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2016-10-25 14:54 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (322 votes). Check out past polls.