Author Topic: changing DFS selection  (Read 145 times)

koawmfot

  • Newbie
  • *
  • Posts: 9
changing DFS selection
« on: February 22, 2019, 01:28:01 pm »
hey guys, long time since i have been here.

trying to write a script for XP to change the DFS referral selection on startup

https://docs.microsoft.com/en-us/windows/desktop/api/lmdfs/nf-lmdfs-netdfssetclientinfo

i'm weak on my WB skills these days.  any chance i can get a pointer or too for what i need to do here?

dll_NetAPI32=DllLoad(DirWindows(1):"Netapi32.dll")
bb_Active = BinaryAlloc(4)
BinaryPoke(bb_Active,0,4)
ret_NetDfsSetClientInfo=DllCall(dll_NetAPI32, long:"NetDfsSetClientInfo", lpwstr:"\\mydomain.com\sysvol", lpwstr:"\\specificserver.mydomain.com\sysvol", lpwstr:"", long:101, lpbinary:bb_Active)
pause("", ret_NetDfsSetClientInfo)
 

my return is invalid parameter.  once i have a working call i will clean this all up and write it correctly, i just need to see if this will work in the first place.  let me know what you think and thanks as always for your help.

dg

td

  • Tech Support
  • *****
  • Posts: 2849
    • WinBatch
Re: changing DFS selection
« Reply #1 on: February 22, 2019, 02:06:20 pm »
Assuming it is correct, the MSFT documentation indicates that the function you are attempting to call is not available until Windows Vista so it won't fly on XP.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

koawmfot

  • Newbie
  • *
  • Posts: 9
Re: changing DFS selection
« Reply #2 on: February 22, 2019, 02:11:55 pm »
i noticed that too, but it was referenced in an earlier thread from 2005 as available on win2k so i believe the documentation is just a little off/

see post #3

https://forums.tomshardware.com/threads/setting-preferred-dfs-host.1129406/

edit:  i also just checked netapi32.dll from XP in dependancy walker and can see the NetDfsSetClientInfo is a listed function.

td

  • Tech Support
  • *****
  • Posts: 2849
    • WinBatch
Re: changing DFS selection
« Reply #3 on: February 22, 2019, 02:45:20 pm »
An entry point does not a callable Windows API function make but that is a story for another day...

Assuming for the moment that the function is, well, functional on XP, what exactly do mean by  "my return is invalid parameter"?  Are you referring to the Win32/network error code or to the WinBatch (WIL) error?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

koawmfot

  • Newbie
  • *
  • Posts: 9
Re: changing DFS selection
« Reply #4 on: February 22, 2019, 03:41:44 pm »
I believe it will work, i am guessing it is the API call when you hit "Set Active" in the Windows Explorer Properties tab for DFS.

yes, 87 is the return code from the DllCall function, which in System Error Codes is "Invalid Parameter". 

i stopped writing for a few years, so i am rusty on understanding the buffer and what needs to go in it. 

I can mess with the first three string params.

I need to know if the "Level" parameter is ok as 'long:101' or if i need to stick that in a buffer?

And the lpbyte parameter looks like it should be a buffer with 0x4 as the data inside.

it really looks like a basic function and this should be easy.  you gotta help me clean the rust off my skills a bit :)

td

  • Tech Support
  • *****
  • Posts: 2849
    • WinBatch
Re: changing DFS selection
« Reply #5 on: February 22, 2019, 07:04:20 pm »
Speaking from first-hand experience, I wouldn't make any assumptions about which API the Windows shell is calling unless you have done the reverse engineering.

That aside, your DllCall looks fine in terms of parameter types and relationship to C convention types.  I may be missing something - it happens more often than I like to admit - but your problem might have more to do with the content of your strings than any DllCall related issues.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade