Page 1 of 2 12>
Topic Options
#158897 - 2006-03-13 09:43 AM Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Seem to keep having trouble converting this to working KiXtart code.

Can someone convert it to working KiXtart code please.

I keep getting an error passing the flag in the last array when I set it in parameter.
 
Code:
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT:// " & strComputer & "/kenmyer ")
objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag
objUser.SetInfo


 

Top
#158898 - 2006-03-13 09:57 AM Re: Help converting VBS code to KiXtat
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Code:

$ADS_UF_DONT_EXPIRE_PASSWD = &10000
$strComputer = "atl-win2k-01"
$objUser = GetObject("WinNT:// " + $strComputer + "/kenmyer")
$objUserFlags = $objUser.Get("UserFlags")
$objPasswordExpirationFlag = $objUserFlags | $ADS_UF_DONT_EXPIRE_PASSWD
$objUser.Put("userFlags", $objPasswordExpirationFlag)
$objUser.SetInfo



I think...

Top
#158899 - 2006-03-13 10:10 AM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Nope, thanks for trying but same error I get.

ERROR : expected ')'!
Script: C:\A\AD\test.kix
Line : 7


This is line 7
$objUser.SetInfo

But I think Line 6 is the one really causing the error.


Edited by NTDOC (2006-03-13 10:11 AM)

Top
#158900 - 2006-03-13 10:13 AM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well late here and I have work in the morning. I'll check back in the morning.

Thanks again.

Top
#158901 - 2006-03-13 10:16 AM Re: Help converting VBS code to KiXtat
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
check out the reference for the put() function.
I doubt it supports what we are throwing at it.
_________________________
!

download KiXnet

Top
#158902 - 2006-03-13 01:59 PM Re: Help converting VBS code to KiXtat
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
doc give this a try:
Code:

$objPasswordExpirationFlag = $objUserFlags + $ADS_UF_DONT_EXPIRE_PASSWD

_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#158903 - 2006-03-13 02:36 PM Re: Help converting VBS code to KiXtat
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

doc give this a try:
Code:

$objPasswordExpirationFlag = $objUserFlags + $ADS_UF_DONT_EXPIRE_PASSWD






No Doc, don't try that. Stick with the bitwise "|", it's fine.

Top
#158904 - 2006-03-13 02:46 PM Re: Help converting VBS code to KiXtat
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Doc, you got an extra space in your WinNT string and its screwing up the WinNT path:

$objUser = GetObject("WinNT:// " + $strComputer + "/kenmyer")

Top
#158905 - 2006-03-13 06:41 PM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Thanks Jooel for the bitwise code and thanks Shawn for the space in the name, that was the final key.

Code now works as suggested by Jooel and removing the space as suggested by Shawn.

Thanks again guys.

Top
#158906 - 2006-03-13 07:20 PM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Quote:

Quote:

doc give this a try:
Code:

$objPasswordExpirationFlag = $objUserFlags + $ADS_UF_DONT_EXPIRE_PASSWD






No Doc, don't try that. Stick with the bitwise "|", it's fine.




Richard, what's up with that? Benny's code worked fine too.

Top
#158907 - 2006-03-13 07:25 PM Re: Help converting VBS code to KiXtat
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
If the bit was already set then adding would change other bits as the two values would be summed. You only want to adjust the single bit.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158908 - 2006-03-13 07:30 PM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Thanks for the reply Howard. I understand what you mean.

Wasn't sure why exactly as I didn't spend the time to work it out that far, but I was thinking concatenation and not bitwise as to why it was or would be wrong.


yeah it toggles it when you use the + and either enables or leaves it alone with the |

Thanks Howard.


Edited by NTDOC (2006-03-13 07:34 PM)

Top
#158909 - 2006-03-13 09:15 PM Re: Help converting VBS code to KiXtat
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It may "toggle" it, but the carry bit would also affect the adjacent bit. I thought you were 01 of the 10 types of people that understood binary?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158910 - 2006-03-13 09:27 PM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
LOL, well you see I removed that signature already
Top
#158911 - 2006-03-13 11:42 PM Re: Help converting VBS code to KiXtat
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
No, I don't see. I don't show sigs and avatars. My pages load quicker and there is less scrolling to do. Not to mention how annoying some of them are.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158912 - 2006-03-14 10:07 AM Re: Help converting VBS code to KiXtat
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Benny asked the same question, so a quick explanation for anyone else who comes across this thread and who is not binary-flag-aware.

It is common practice to store similar flags as bits (on or off) in a single datum.

Using an eight bit field as an example, you have eight possible flags. Their positions and values are:
Code:
76543210
--------
00000001 - 1
00000010 - 2
00000100 - 4
00001000 - 8
00010000 - 16
00100000 - 32
01000000 - 64
10000000 - 128



You can explicitly set the flags in the field just by adding the values together, so to set the flags at positions 1 and 6 you would use 2+64 = 66. However this also sets all the other flags to zero which may not be what you want.

If you use the bitwise OR which is "|" in KiXtart, then only the flags that you specify will be set - the other flags will be left unchanged.

You cannot simply add the flag values to the existing value. If you do this then (as Les says) the flag will "carry" to the next higher position. This is easy to see with an example.

Say you try to set flag 1 four times using addition. This is what would happen:
Code:

76543210
--------
00000000 - Start, add 2 (the value of flag 1)
00000010 - SUCCESS! flag #1 is set. Now add it again.
00000100 - Oh-oh! The flag is unset, and worse flag #2 is set.
00000110 - Success! We've set flag #1 again
00001000 - Oh-oh! Flag#1 is unset and so is flag #2, but now flag #3 is set!



As you can see, it's all turned into a horrible mess.

Even when you are setting bit-fields explicitly it is good programming practice to only use bitwise operators to manipulate them. Not only does this serve as a reminder of what you are changing, but it helps to avoid costly hard to find errors if the field use should later change.

To complete the story, you can safely use simple addition and subtraction to change bit settings, but only if you check the setting first:
Code:

; To set the flag:
If Not ($objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD)
$objUserFlags=$objUserFlags + $ADS_UF_DONT_EXPIRE_PASSWD
EndIf

; To clear a flag
If $objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD
$objUserFlags=$objUserFlags - $ADS_UF_DONT_EXPIRE_PASSWD
EndIf


Top
#158913 - 2006-03-14 10:14 AM Re: Help converting VBS code to KiXtat
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Thanks a lot for the explanation there Richard.
Top
#158914 - 2006-03-14 12:32 PM Re: Help converting VBS code to KiXtat
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I liked the explanation so much that I had to cast my rating in http://www.kixtart.org/ubbthreads/showprofile.php?Cat=0&User=362
_________________________
!

download KiXnet

Top
#158915 - 2006-03-14 01:14 PM Re: Help converting VBS code to KiXtat
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Richard, I think it would be better to be consistent and use the bit-wise NOT (~) operator when turning off a flag instead of subtracting.
Code:
; To clear a flag:
If $objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD
$objUserFlags=$objUserFlags & ~$ADS_UF_DONT_EXPIRE_PASSWD
EndIf



Code:
; To set the flag:
If Not ($objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD)
$objUserFlags=$objUserFlags | $ADS_UF_DONT_EXPIRE_PASSWD
EndIf

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158916 - 2006-03-14 01:31 PM Re: Help converting VBS code to KiXtat
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Richard, I think it would be better to be consistent and use the bit-wise NOT (~) operator when turning off a flag instead of subtracting.




Yes, the last examples were demonstrations of how to manipulate the bits using simple math instead of bitwise operations, they are not how I would recommend that the operations are performed.

Using the bitwise operations means that you do not need the conditionals at all.

I hope that clarifies things.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.075 seconds in which 0.025 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