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

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
Cantrel
Messages: 14
Registration: Sep 29, 2020 - 1:49 p.m.

February 16, 2021 - 09:41

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.
Cantrel
Messages: 14
Registration: Sep 29, 2020 - 1:49 p.m.

February 16, 2021 - 12:35

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?
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

February 16, 2021 - 1:56 PM

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"
Locked