WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

wntUserGetDat and Logon_hours Flag

Keywords: 

Question:

Has anyone used the wntUserGetDat function with the "logon_hours" flag?

I have been unable to decipher the string I am receiving from winbatch. The help file claims to give a 21-byte string, I am receiving a 42 byte string in hexadecimal format.

The call is as follows:

AddExtender("WWWNT34I.DLL")
flags=wntUserGetDat("\\cspdc","smithj","logon_hours")
Can someone give me a little insight on this?

Answer:

There is a 21 byte string that contains the information in a binary format.

WinBatch cannot handle that kind of binary value so it converts it to acsii hexadecimal format, doubling the size. So yes the string you get back is 42 bytes long but it represents only 21 bytes of data.

Each byte is 8 bits.

21 * 8 = 168
there are 168 unique bits of data.
Each week has 7 days
There are 24 hours in a day

7 * 24 = 168

There are 168 hours in a week.

Each bit represents one hour. If the bit is set the user may logon during that hour.
There may be a GMT offset involved.
The easiest way it to set a user up exactly how you want them with user manager, then do a wntUserGetDat on the string and save it.

You can use that same string in a wntUserSetDat.

And another user phrases the answer this way...

You are getting 21 bytes of information encoded as hexadecimal digits. Each pair of digits (nibbles) represents one byte of the actual data. Use the WILX34I.DLL extender to make the xBaseConvert() function available if you want to convert this data to a numeric value.

Each bit that is on represents one hour, starting at 00:00 on, I think, Monday. As you progress through the hours, you cross over into the next day. At 1 hour per bit you get 8 hours per byte. At 24 hours in a day, you get 3 bytes per day and multiplying by 7 days you get 21 bytes.

The time is biased relative to GMT. Your local system will apply your time zone information when processing the logon hours restrictions. This complicates matters a bit when figuring out how to properly manipulate the logon hours setting. User Manager [for Domains] automatically applies the time zone information of the computer on which it is running when diplaying this information and when allowing you to modify it. As an experiment, disable just a single hour at some readily identifiable point like the start, middle or end of one or more days during the week. Then use wntUserGetDat() to obtain the hex string and see what it looks like since it will be stored biased by GMT and not your local time zone.


NT_Logon_Hours_UDF.wbt

#DefineFunction LH_IsHourOn(sLogonHours,nDay,nHour,nTZOffset)

Title01 = 'LH_IsHourOn()'

; Validate our input parameters

if (StrLen(sLogonHours) != 42)
  TempMsg = StrCat(Title01,': Error!  sLogonHours is not 42 characters in length.')
  IntControl(79,-1,7000,TempMsg,0)
endif

if (nDay < 0 || nDay > 6)
  TempMsg = StrCat(Title01,': Error!  nDay is < 0 or is > 6.')
  IntControl(79,-1,7000,TempMsg,0)
endif

if (nHour < 0 || nHour > 23)
  TempMsg = StrCat(Title01,': Error!  nHour is < 0 or is > 23.')
  IntControl(79,-1,7000,TempMsg,0)
endif

if (nTZOffset < -12 || nTZOffset > 12)
  TempMsg = StrCat(Title01,': Error!  nTZOffset is < -12 or > 12.')
  IntControl(79,-1,7000,TempMsg,0)
endif

; Convert our day & hour into a bit offset.

BitOffset = (nDay * 3 * 8) + nHour

; Apply the TZ value to it

BitOffset = BitOffset + nTZOffset

; Now test to see if we have "wrapped" around the end of our bit range

if (BitOffset > 167)
  ; We went past the end of the range, wrap around from the beginning
  BitOffset = (168 - BitOffset) - 1
endif

if (BitOffset < 0)
  ; We went past the beginning of the range, wrap around from the end
  BitOffset = 168 + BitOffset
endif

; Convert our bit offset value into a hex digit pair # and a bit #.

HexPairNum = BitOffset / 8
BitNum = BitOffset mod 8

; Extract the hex digit pair from the logon hours string

HexPair = StrSub(sLogonHours, (HexPairNum * 2) + 1, 2)

; Set up a 1 byte binary buffer to use for base conversion operations.
; This is done so we don't need the WILX extender loaded just for this
; particular UDF to work properly.

hBuf = BinaryAlloc(1)

if (hBuf == 0)
  TempMsg = StrCat(Title01,': Error!  hBuf is zero.')
  IntControl(79,-1,7000,TempMsg,0)
endif

; Poke our hex string into a binary buffer

BinaryPokeHex(hBuf,0,HexPair)

Byte = BinaryPeek(hBuf,0)

if (Byte & (1 << BitNum))
  bResult = @TRUE
else
  bResult = @FALSE
endif

hBuf = BinaryFree(hBuf)


return bResult

#EndFunction

Article ID:   W14385
Filename:   wntUserGetDat and Logon_hours Flag.txt
File Created: 2005:01:26:12:16:22
Last Updated: 2005:01:26:12:16:22