#197629 - 2010-02-02 10:06 PM
UNC: EXIST and RUN doesn't seem to be working.
|
Whyre
Fresh Scripter
Registered: 2006-06-19
Posts: 5
|
I'm writing a script to check which domain groups a user is a member of, then check for a .CMD file with the same name as the group to execute if it exists. It's still pretty rough, but I've gotten most of the parsing done. However, the EXIST or even the RUN doesn't seem to properly check for the file or run it.
break on
$Index = 0
$ext=".cmd"
$quote = chr(34)
? @LDRIVE
$LDrive = @LSERVER+"\Netlogon\"
? $Ldrive
? @DOMAIN
? LEN(@DOMAIN)
DO
$DomainGroup = ENUMGROUP($Index)
$Index = $Index + 1
IF INSTR($DomainGroup,@DOMAIN)
$Group = SUBSTR($DomainGroup, LEN(@DOMAIN)+2)
$Script = $quote+$LDRIVE+$Group+$ext+$quote
IF EXIST($Script)
? $Script
RUN $Script
ENDIF
ENDIF
UNTIL Len($DomainGroup) = 0
According to searches, EXIST should have no problem with UNC. I've tried it with and without the quotes to no avail. I'm running it with domain admin privledges to ensure there isn't a permissions snafu causing the issue.
I'm hoping it's something obvious that I'm just not seeing.
Thanks
|
|
Top
|
|
|
|
#197632 - 2010-02-02 11:36 PM
Re: UNC: EXIST and RUN doesn't seem to be working.
[Re: Allen]
|
Whyre
Fresh Scripter
Registered: 2006-06-19
Posts: 5
|
When I comment the exist statement, $Script is populated correctly:
\\MISCHIEVOUS\NETLOGON\
\\MISCHIEVOUS\Netlogon\
MISFL
5
\\MISCHIEVOUS\Netlogon\Domain Users.cmd
\\MISCHIEVOUS\Netlogon\Technicians.cmd
<snip>
Since several user groups have spaces, that was the reason for the quotes, I've removed the quotes for the above example. There is indeed a \\MISCHIEVOUS\Netlogon\Technicians.cmd, but it doesn't seem to be acknowledged by EXIST, and RUN doesn't seem to execute it either.
I'm running this on an x64 version of Windows 7 with KiXtart 4.61. Anything else I can do to produce more information as to why the files don't EXIST or RUN?
|
|
Top
|
|
|
|
#197634 - 2010-02-03 12:17 AM
Re: UNC: EXIST and RUN doesn't seem to be working.
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
I just ran the following script on Win7 x64 and it worked fine. It just checks if kix32.exe exists on a shared drive and then runs it to show the help dialog.
Change to match your server/share, etc. If it doesn't work, I would lean towards spelling or permissions.
$server="windows7-pc2"
$share="shared"
$file="kix32.exe"
$cmd="\\" + $server + "\" + $share + "\" + $file
? $cmd
if exist($cmd)
? "Found it"
shell $cmd + " /?"
else
? "Not"
endif
Edited by Allen (2010-02-03 12:23 AM)
|
|
Top
|
|
|
|
#197635 - 2010-02-03 12:21 AM
Re: UNC: EXIST and RUN doesn't seem to be working.
[Re: Allen]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Once again, the SPACE monster rears its ugly head!
DOS - still, in the world of long file names and allowed special characters - still CHOKES on these. What you can do easily in Windows and Kix requires a bit more consideration when you invoke the shell. Eliminating spaces can go a long way in making things work better.
So - you have a group called "Some Special Bunch Of Users" - the spaces are OK. You want to run a command based on the group, so you think "Some Special Bunch Of Users.CMD" is the way to go. Well, not so much..
Simple change - your batch file is called "SomeSpecialBunchOfUsers" and you tell Kix to remove the spaces from the group name before adding the ".CMD" extension. Here's howDo
$DomainGroup = ENUMGROUP($Index)
$DomainGroup ?
$Index = $Index + 1
IF INSTR($DomainGroup,@DOMAIN)
$Group = Join(Split(SubStr($DomainGroup, Len(@DOMAIN) + 2), ' '), '')
$Script = $LDRIVE + $Group + $ext
If Exist($Script)
'RUNNING ' $Script ?
Shell $Script
@SERROR ?
EndIf
EndIf
Until Not $DomainGroup Of course, you could replace the spaces with underscores just as easily by inserting a "_" character between the empty pair of quotes on the Join/Split line.
This isn't a "fix" so much as a method to overcome the limitations that still exist when calling batch files. You'd be surprised by how many other applications still suffer from this - Oracle, for example, will choke if your TEMP var references a path with spaces.. change it to C:\Temp and it's happy. 
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#197642 - 2010-02-03 02:22 PM
Re: UNC: EXIST and RUN doesn't seem to be working.
[Re: Allen]
|
Whyre
Fresh Scripter
Registered: 2006-06-19
Posts: 5
|
My goal is making a simple set of logon scripts for other non-kix administrators to follow. If they need a drive mapped, or a variable set for some specific application, simply making a user a member of that group with permissions to the share/application and creating a batch file of the same name would be executed at logon.
|
|
Top
|
|
|
|
#197643 - 2010-02-03 02:31 PM
Re: UNC: EXIST and RUN doesn't seem to be working.
[Re: Glenn Barnas]
|
Whyre
Fresh Scripter
Registered: 2006-06-19
Posts: 5
|
Once again, the SPACE monster rears its ugly head! DOS - still, in the world of long file names and allowed special characters - still CHOKES on these. What you can do easily in Windows and Kix requires a bit more consideration when you invoke the shell. Eliminating spaces can go a long way in making things work better. So - you have a group called "Some Special Bunch Of Users" - the spaces are OK. You want to run a command based on the group, so you think "Some Special Bunch Of Users.CMD" is the way to go. Well, not so much.. Simple change - your batch file is called "SomeSpecialBunchOfUsers" and you tell Kix to remove the spaces from the group name before adding the ".CMD" extension. Here's how Do
$DomainGroup = ENUMGROUP($Index)
$DomainGroup ?
$Index = $Index + 1
IF INSTR($DomainGroup,@DOMAIN)
$Group = Join(Split(SubStr($DomainGroup, Len(@DOMAIN) + 2), ' '), '')
$Script = $LDRIVE + $Group + $ext
If Exist($Script)
'RUNNING ' $Script ?
Shell $Script
@SERROR ?
EndIf
EndIf
Until Not $DomainGroupOf course, you could replace the spaces with underscores just as easily by inserting a "_" character between the empty pair of quotes on the Join/Split line. This isn't a "fix" so much as a method to overcome the limitations that still exist when calling batch files. You'd be surprised by how many other applications still suffer from this - Oracle, for example, will choke if your TEMP var references a path with spaces.. change it to C:\Temp and it's happy.  Glenn
Very handy, I'll keep this snippet for future use.
|
|
Top
|
|
|
|
#197644 - 2010-02-03 02:33 PM
Re: UNC: EXIST and RUN doesn't seem to be working. - fixed -
[Re: Allen]
|
Whyre
Fresh Scripter
Registered: 2006-06-19
Posts: 5
|
I just ran the following script on Win7 x64 and it worked fine. It just checks if kix32.exe exists on a shared drive and then runs it to show the help dialog. Change to match your server/share, etc. If it doesn't work, I would lean towards spelling or permissions.
$server="windows7-pc2"
$share="shared"
$file="kix32.exe"
$cmd="\\" + $server + "\" + $share + "\" + $file
? $cmd
if exist($cmd)
? "Found it"
shell $cmd + " /?"
else
? "Not"
endif
Yikes! Spelling strikes again. I just copied and pasted the output of where the file was supposed to be and it could not run. My script works fine when the file you're looking for actually does exist. Oy, sorry to bother you all with something so silly. Thank you all for all your help - good advice.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 601 anonymous users online.
|
|
|