changing DFS selection

Started by koawmfot, February 22, 2019, 01:28:01 PM

Previous topic - Next topic

koawmfot

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

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

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

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

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

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