%Username% is always System!

Antworten
Benutzeravatar
ebarriosjr
Beiträge: 26
Registriert: 24 Jun 2014, 11:03

%Username% is always System!

Beitrag von ebarriosjr »

Hello,

i have a littel problem, i am trying to intall a software in the %AppdataDir% of a couple of user but the route is always wrong. When i display the %Username% it says it is always System. What can i do to get the name of the logged user?

Thanks

P.D: The %AppData% is always: C:\Windows\system32\config\systemprofile\AppData\Roaming and i want it to be C:\Users\<username>\AppData\Roaming
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: %Username% is always System!

Beitrag von n.wenselowski »

Hello,

the username System is correct because the opsi-winst runs in the System-context.

There are some switches to winst sections that begin with /AllNTUser. You should have a look at them in the winst manual.

Otherwise we would need some more information on how the section looks and how it is called.


With kind regards

Niko

Code: Alles auswählen

import OPSI
Benutzeravatar
ebarriosjr
Beiträge: 26
Registriert: 24 Jun 2014, 11:03

Re: %Username% is always System!

Beitrag von ebarriosjr »

Hello again,

i need to get the name of user that is logged or the last logged user will work to. I trie to copy this data from the registry with:

Code: Alles auswählen

Set $local_user$ = GetRegistryStringValue("[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders] AppData")
and with

Code: Alles auswählen

Set $local_user$ = GetRegistryStringValue("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI] LastLoggedOnSAMUser")
and with

Code: Alles auswählen

Set $local_user$ = GetRegistryStringValue("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI] LastLoggedOnUser")
But it comes always empty....

The programm that i am triying to in stall needs to go in the C:\Users\<username>\AppData\Roaming. How can i know the name of the logged user? I cant install it for all users.....

Please help me...

Best regards
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: %Username% is always System!

Beitrag von n.wenselowski »

Hello,

the easiest way is probably to do this with the User Profile Management extension because then you can use i.e. GetLoggedInUser.
Also what I am thinking of is to use an opsi service call like hostControlSafe_getActiveSessions to see who is logged on.
But I am not specialist for opsiscript so there may be an easier way to do this.

Also I recommend a support contract.


With kind regards

Niko

Code: Alles auswählen

import OPSI
Benutzeravatar
ebarriosjr
Beiträge: 26
Registriert: 24 Jun 2014, 11:03

Re: %Username% is always System!

Beitrag von ebarriosjr »

Hi again,

i am using the evaluation of the User Profile Management extension. And if i set $User$ = GetLoggedInUser i get the right user. But all the varibles %AppDataDir%, etc etc are not set correctly. The installer that i am using generates a token based on this variables.

Is there any command to run the installer as the loggedinUser with admin rights?

Maybe winbatch /RunAsLoggedInUser or something like that?

Best regards
Benutzeravatar
d.oertel
uib-Team
Beiträge: 3327
Registriert: 04 Jun 2008, 14:27

Re: %Username% is always System!

Beitrag von d.oertel »

Hi,

running with the user-profile-management extension in profile mode %AppdataDir% should be correct for the logged in user.

What did you get ?
Maybe winbatch /RunAsLoggedInUser or something like that?
This will start the process in the context of the logged in user (while in profile mode) .

regards

d.oertel


Vielen Dank für die Nutzung von opsi. Im Forum ist unser Support begrenzt.

Für den professionellen Einsatz und individuelle Beratung empfehlen wir einen Support-Vertrag und eine Schulung.
Gerne informieren wir Sie zu unserem Angebot.

uib GmbH
Telefon: +49 6131 27561 0
E-Mail: sales@uib.de


ritsovih
Beiträge: 38
Registriert: 20 Mär 2013, 09:25

Re: %Username% is always System!

Beitrag von ritsovih »

just a fyi, since d.oertel's suggestion (user-profile-management) is probably better, but it is possible to run programs as the logged on user, even if you start the original process as SYSTEM

https://www-304.ibm.com/support/docview ... wg21506033

https://github.com/MicksMix/RunAsLou/bl ... nAsLOU.exe (didn't test this one myself)

both allow you to run programs/scripts as the logged on user, provided the original process starts as SYSTEM

for instance if the logged on user is JoeSchmoe : running RunAsCurrentUser-2.0.3.1.exe notepad as SYSTEM will start notepad.exe as JoeShmoe

this isn't much use for normal opsi operation, since most opsi actions run at system boot, before any user (except SYSTEM) is logged on.
Antworten