Page 1 of 1 1
Topic Options
#197629 - 2010-02-02 10:06 PM UNC: EXIST and RUN doesn't seem to be working.
Whyre Offline
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.
 Code:
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
#197630 - 2010-02-02 10:29 PM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Whyre]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Welcome to KORG!

Well, running this on my system seems to work, once I remove the $quote definition. I just set
$Quote = ''
in my copy and it worked just as you'd expect.

Sometimes it's the simple things that bite you!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197631 - 2010-02-02 10:30 PM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Whyre]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Why don't you display this line after creating it and see if it looks like you expect.

$Script = $quote+$LDRIVE+$Group+$ext+$quote
? $script

I see no advantage for using $quote. In fact, I don't think you even need it there, and it could be what is causing your problems

$Script = $LDRIVE + $Group + $ext

Top
#197632 - 2010-02-02 11:36 PM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Allen]
Whyre Offline
Fresh Scripter

Registered: 2006-06-19
Posts: 5
When I comment the exist statement, $Script is populated correctly:

 Code:
\\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
#197633 - 2010-02-02 11:48 PM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Whyre]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Curious... what's in these batch/cmd files that we couldn't do in kix?
Top
#197634 - 2010-02-03 12:17 AM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Allen]
Allen Administrator Online   shocked
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.

 Code:
 
$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 Administrator Offline
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 how
 Code:
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 $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! \:D

Top
#197642 - 2010-02-03 02:22 PM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Allen]
Whyre Offline
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 Offline
Fresh Scripter

Registered: 2006-06-19
Posts: 5
 Originally Posted By: Glenn Barnas
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
 Code:
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 $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


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 Offline
Fresh Scripter

Registered: 2006-06-19
Posts: 5
 Originally Posted By: Allen
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.

 Code:
 
$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
#197645 - 2010-02-03 02:44 PM Re: UNC: EXIST and RUN doesn't seem to be working. [Re: Whyre]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
That's why our login script uses an external configuration file with basic Resource Records to define what, where, and various authorization methods.
No coding is needed (and the script is compiled to prevent changes), allowing non-programmer admins to create anything from basic to complex login procedures.

Glenn

And yes, spelling DOES count! ;\)
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 601 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.065 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org