Windows 10 – Perl与dsadd / dsquery

几个月前,我创build了一个用于将用户添加到Active Directory的perl脚本。 在Windows 7上它运行良好。 在Windows 10 Perl不能运行“dsquery”或“dsadd”,但我真的不明白这一点。

当我从同一个命令行运行“dsquery”时,它工作。 尝试用perl脚本…它不会!

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

(=命令dsquery无法find…)

一些来自Perl脚本的代码片段:

 $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;} 

此时它已经停止。 但是,当我运行:

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

有用。

这里发生了什么? 任何人都可以忍受吗?

干杯,卢卡斯

我猜你已经在64位操作系统上安装了32位的Perl。 在Windows 10 AMD64的C:\Windows\SysWOW64\没有32位版本的dsquery.exe 。 从“运行”对话框比较以下结果。

用32位cmd

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

然后明确使用64位cmd

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

要不就

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

如果您确实想从32位环境运行64位dsquery.exe ,请尝试使用sysnative别名。

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

在你的脚本中试试这个,不保证Perl不会扼杀它。

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