Windows 10 – Perl vs. dsadd/dsquery

active-directoryperlwindowswindows 10

I created a perl script for adding users to Active Directory a few months ago. On Windows 7 it runs fine. On Windows 10 perl is not able to run "dsquery" or "dsadd" but I can really not understand this.

When I run "dsquery" from the same command line, it works. Trying with the perl script… It won't!

Der Befehl "C:\Windows\System32\dsquery.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

(= Command dsquery could not be found…)

Some code snippets from the perl script:

$datetime = strftime("%d.%m.%Y %H:%M:%S", localtime);
&GetOptions     ("-v=s"    => \$fname,
             "-n=s"    => \$sname,
             "-u=s"    => \$uname,
             "-p=s"    => \$pwd,
             "-noshare" =>\$noshare,
             "-test"   =>\$test,
             "-noquota"   =>\$noquota,
             "-sshpw=s"   =>\$sshpw );

unless ($fname) {                
print "Vorname: ";
$fname = <STDIN>;
chomp $fname;}

unless ($sname) {
print "Nachname: ";
$sname = <STDIN>;
chomp $sname;}

unless ($uname) {
$uname =  substr($fname, 0, 1);
$uname = "$uname.$sname";}
$uname = lc($uname);

if (`C:\\Windows\\System32\\dsquery.exe user -samid $uname`){
print "Benutzer $uname existiert bereits!";
exit;}

At this point it already stops.
But, when I run:

c:\windows\system32\dsquery.exe user -samid ANYUSER 

it works.

What is happening right here? Can anyone undestand this??

Cheers,
Lukas

Best Answer

I'm guessing you've a 32 bit install of Perl on a 64 bit OS. There isn't a 32 bit version of dsquery.exe in C:\Windows\SysWOW64\ on Windows 10 AMD64. From the 'Run' dialog compare the results of the following.

With 32 bit cmd:

C:\Windows\SysWOW64\cmd.exe /K C:\windows\system32\dsquery.exe

Then explicitly using 64 bit cmd:

C:\Windows\System32\cmd.exe /K C:\windows\system32\dsquery.exe

Or just

DIR C:\Windows\SysWOW64\dsq*.*
DIR C:\Windows\System32\dsq*.*

If you really want to run 64 bit dsquery.exe from a 32 bit environment try using the sysnative alias.

C:\Windows\SysWOW64\cmd.exe /K C:\windows\sysnative\dsquery.exe

Try this in your script, no guarantees that Perl won't just choke on it.

if (`C:\\Windows\\sysnative\\dsquery.exe user -samid $uname`)