Page 1 of 1

A package that checks if a directory is present in the user's profile

Published: February 16, 2021 - 09:41
by Cantrel
Hello,

We need to check if a directory is present on the desktops of machines used with a generic Active Directory account.
The directory must be located on the desktop of that account.

We would like to deploy a package to the affected machines that returns some result in their audit (for example, whether the directory is present or not).

We have written the code in the `def audit` section of the package for this purpose.

We are trying to retrieve the name of the user currently logged into the machine to build the search path (c:\users\'username'\desktop\...).

However, we have tried several methods, but they either return the machine name or incorrect information:
`os.environ['USERPROFILE']` returns `C:\WINDOWS\system32\config\systemprofile`, `
win32api.GetUserName()` returns `SystÞme`,
`os.getenv('username')` returns the machine name (e.g., `my-machine$`),
`getpass.getuser()` returns the machine name (e.g., `my-machine$`).

Do you know why? We've been stuck for a while.

Thank you.

Re: Package that checks if a directory is present in the user's profile

Published: February 16, 2021 - 12:35 PM
by Cantrel
It seems this stems from the fact that wapt uses the system account to perform its actions.

Therefore, we need to use the session_setup component to interact with the user session, but apparently, there are no logs of the actions performed within the session_setup component. Can you confirm this?

Re: Package that checks if a directory is present in the user's profile

Published: February 16, 2021 - 1:56 PM
by sfonteneau
Given what you want to do, there's no need to perform a session_setup:

use the audit:

Code: Select all

list_error = []
for p in get_local_profiles():
    print('Test for %s' % p['user'])
    if not isdir(makepath(p['profile_path'],'Desktop','foldertest')) :
        list_error.append( 'Error for %s folder not found' % p['user'] )

if list_error:
    print(list_error)     
    return "ERROR"
else:
    return "OK"