Jump to content

Dll call and GetWindowsDirectory


 Share

Recommended Posts

I know that there is a macro in autoit to give you the windows directory but this does not give the personal windows directory I need to find when my program is running in a WTS session. I thought I could do this using Kernel32.dll and the function GetWindowsDirectory but I cannot seem to find the parameters I need to call to make this work. From MSDN I got this

UINT GetWindowsDirectory ( LPTSTR lpbuffer, UINT usize)

see this link http://msdn2.microsoft.com/en-us/library/ms724454.aspx

How does this work with the DllCall function?

Please help I just can't work this out.

Link to comment
Share on other sites

Thanks for that I did not realise is was an array that was being returned. Here is my code however it does not give the response I expected

$windowsdirectory = DllCall("Kernel32.dll", "int", "GetWindowsDirectory", "str", 0, "int", 256)
        MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$windowsdirectory' & @lf & @lf & 'Return:' & @lf & $windowsdirectory[1] & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX

This still gives me C:\WINDOWS which is the same as the macro in autoit.

According to the documententaion on MSDN unless my application is Terminal-Services-aware then this function will return the path of the system windows directory

I was looking to use User32.dll GetSystemMetrics with the index 0x1000 for SM_REMOTESESSION to detect if the session was Terminal server but I don't know how to use this to then get the correct private windows directory."http://msdn2.microsoft.com/en-us/library/ms724385.aspx"

Currently I am only testing with a compiled version of the above script.

Anyone have any ideas?

Link to comment
Share on other sites

This still gives me C:\WINDOWS which is the same as the macro in autoit.

According to the documententaion on MSDN unless my application is Terminal-Services-aware then this function will return the path of the system windows directory

The private Windows directory for a WTS user will only be different from the system Windows directory if you have specified so through the User Manager administrative tool. Are you testing this with a WTS user account that has a redirected Windows directory?
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

The private Windows directory for a WTS user will only be different from the system Windows directory if you have specified so through the User Manager administrative tool. Are you testing this with a WTS user account that has a redirected Windows directory?

Yes there is a private windows directory for the user as the application I would be automating places a folder there.

I really am stumped on this I have done a bodge fix of checking the userprofile directory for the existence of a private windows or winnt directory but I would really like to know the correct windows directory being used. The programmer of the application uses the DLL call GetWindowsDirectory and as it stated in the MSDN documnetation this will return the private windows directory if in a WTS session.

I just need to know how to check for this and pass this to the dll call?

I have now got the GetSystemMetrics Dll call 0x1000 working to indicate that the exe is running via a remote session thanks to PaulIA's AUto3Lib finctions but still need to know how to get the private windows directory

Edited by Lee Evans
Link to comment
Share on other sites

The programmer of the application uses the DLL call GetWindowsDirectory and as it stated in the MSDN documnetation this will return the private windows directory if in a WTS session.

This might be worth looking at again. It appears to be backwards from what your programmer is telling you. If his app is TS aware, it should be returning the system Windows directory, not the private Windows directory.

Terminal Services: If the application is running in a Terminal Services environment, each user has a private Windows directory. There is also a shared Windows directory for the system. If the application is Terminal-Services-aware (has the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag set in the image header), this function returns the path of the system Windows directory, just as the GetSystemWindowsDirectory function does. Otherwise, it retrieves the path of the private Windows directory for the user.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

This might be worth looking at again. It appears to be backwards from what your programmer is telling you. If his app is TS aware, it should be returning the system Windows directory, not the private Windows directory.

Here is the quote from the MSDN article on the GetWindowsDirectroy dll function

If the application is Terminal-Services-aware (has the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag set in the image header), this function returns the path of the system Windows directory, just as the GetSystemWindowsDirectory function does. Otherwise, it retrieves the path of the private Windows directory for the user.

As my compiled exe from the above gives me the system Windows directory I assume that AutoIT is terminal server aware otherwise it should give me the private windows directroy. I have tried this with a compiled EXE and also just a script with AutoIT installed.

Link to comment
Share on other sites

As my compiled exe from the above gives me the system Windows directory I assume that AutoIT is terminal server aware otherwise it should give me the private windows directroy. I have tried this with a compiled EXE and also just a script with AutoIT installed.

If you use a PE viewer on your AutoIt exe, you'll see that the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag is not set in the header. If you use UPX to unpack the exe, it's not set on the native AutoIt exe either. AutoIt does not generate TS aware applications.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Strange, must be a different setting with VC7 which is used to compile releases. VC8 is set up to build TS aware.

So now I am really confused! I am downloading PE Viewer to see what it says for my compiled exe (using the latest released version of AutoIT)

I have managed to use the dll call to getsystemmetrics with the indices 0x1000 this tells me that the exe is being run over a remote session so I then check the user profile directory for a windows or winnt directory and then check there for the required folder.

Link to comment
Share on other sites

So now I am really confused! I am downloading PE Viewer to see what it says for my compiled exe (using the latest released version of AutoIT)

I have managed to use the dll call to getsystemmetrics with the indices 0x1000 this tells me that the exe is being run over a remote session so I then check the user profile directory for a windows or winnt directory and then check there for the required folder.

Just did this and now know why I was getting the differences. As Valik stated AutoIT ver3.2.2.0 is terminal server aware as are the compiled scripts. I checked the exe that I was planning to test and it is not terminal server aware there fore AutoIt gives the system windows directory when using dll call and getwindows directory and the test application gives the private windows directory when calling the same dll.

I now understand and have been able to get the same results with my test script through AutoIt by checking if run as a remote session.

Thanks to PaulIA and Valik for their help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...