Page 1 of 1 1
Topic Options
#36850 - 2003-02-22 07:43 PM Admin-related WriteValue Problem
bbpalmer Offline
Fresh Scripter

Registered: 2003-02-22
Posts: 6
Loc: New York City
I am not a true newbie but relatively so. I am pulling my hair out writing a script that is called by a scheduled task with local admin rights. One of the things I am trying to do is dynamically modify the key under HKLM that defines the comment associated with computers when Network Neighborhood is browsed. The comment I am looking for is "UserName (Dell Service Tag) Operating System." This happens in its entirety only if the user has admin rights. If a *normal* user logs in, the key is updated with everything but the name of the user. Examples of the results follow the code.

code:
  
;Build the line command line to modify to the registry
; - $ServiceTag is the Dell service tag assigned earlier
; - $OS is an abbreviated version of @ProductType

$User = @FullName
$Key = "HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters"
$Entry = "srvcomment"
$Expression = $User + "( " + $ServiceTag + ") " + $OS
$DataType = "REG_SZ"

;Write the data to the registry
WriteValue($Key, $Entry, $Expression, $DataType)

The -correct- parameter value if an admin is logged in:
Bruce Palmer (A1B2C) Windows 2000

The -incomplete- parameter value if Joe User is logged in:
(A1B2C) Windows 2000

In attempts to solve this issue, I constructed a .reg file and executed it with the shell command. Same thing. The file was written as expectd but $User was left out if the the account was not a Domain Admin.

One more thing. @FullName is working just dandy for everyone. ?$User before and after the WriteValue line displays correctly despite who is logging in.

Any clues? I could surely use some.

-Bruce

Top
#36851 - 2003-02-22 07:53 PM Re: Admin-related WriteValue Problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Welcome to the board. I'm a bit confused. You say "a script that is called by a scheduled task with local admin rights". What account is that and is it a Local User or Domain User?

If the Task Scheduled script runs under a specific account then that is the account name that @FullName would report. Is this 'Joe User' a Local User or Domain User? What relation is there between 'Joe User' and the account the task runs under?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#36852 - 2003-02-22 08:06 PM Re: Admin-related WriteValue Problem
bbpalmer Offline
Fresh Scripter

Registered: 2003-02-22
Posts: 6
Loc: New York City
WRT the local admin rights: I distributed a task that is run under the administrator account on the local machine. It calls a batch on the network that in turn kicks off the KiXtart script(s) when a user (Joe or otherwise) logs into the network. This part works like a charm and I know that the admin rights are being used because the registry is being modified, albeit incompletely.

@FullName is returning Joe's name, not the adminstrative account that the task is running under (thank goodness, I hadn't considered that!).

After posting, I confirmed that @FullName was working correctly as I reported by adding at() before and after the WriteLine to dump it to the screen. It appears that although the macro is retreiving the name, I am getting an error 5 which I think is access denied.

Does this help define my problem? Thanks very much for your help.

-Bruce

Top
#36853 - 2003-02-22 08:32 PM Re: Admin-related WriteValue Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
is the admin account local or domain?
_________________________
!

download KiXnet

Top
#36854 - 2003-02-22 08:55 PM Re: Admin-related WriteValue Problem
bbpalmer Offline
Fresh Scripter

Registered: 2003-02-22
Posts: 6
Loc: New York City
It is a local admin account. Although I would have prefered to use a network admin account (which by default would have local admin rights) the task would not start unless it was associated with a local admin account.

Thanks for thinking about my problem.

-Bruce

Top
#36855 - 2003-02-22 09:19 PM Re: Admin-related WriteValue Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just like I thought.

the local admin has no rights in network thus the error.
_________________________
!

download KiXnet

Top
#36856 - 2003-02-22 10:13 PM Re: Admin-related WriteValue Problem
bbpalmer Offline
Fresh Scripter

Registered: 2003-02-22
Posts: 6
Loc: New York City
What network rights are being denied? I am writing to the local registry which I apparently have the rights to do as I am successfully modifying it. If @FullName is working and I am successfully assigning that to a variable, why can't I write that variable to the registry just like the other three variables are being written?

-Bruce

Top
#36857 - 2003-02-22 11:25 PM Re: Admin-related WriteValue Problem
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Because you are using the @FULLNAME macro which then must make a call to the Network to find that information. However, the task scheduler service has NO Network access. Thus the error 5 access denied message.

You could run this type of code which might give you what you're looking for.



Break On
$ServiceTag=294012
$OS=@ProductType
$User = ReadValue("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon""AltDefaultUserName")
$Key = "HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters"
$Entry = "srvcomment"
$Expression = $User + " (" + $ServiceTag + ") " + $OS
$DataType = "REG_SZ"
$UpdateKey=WriteValue($Key$Entry$Expression$DataType)


Top
#36858 - 2003-02-22 11:31 PM Re: Admin-related WriteValue Problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I'm sorry but I don't believe you. You must be giving misinformation.

First off, what are you running, AT or Task Scheduler? Task Scheduler is the Scheduled Tasks applet in Control Panel. Scheduled Tasks can indeed run tasks in a domain users context. I know that for sure because I use it all the time.

When you run a script in the context of another user, it is that user's @Fullname that is returned. In the case of the local administrator account that would be blank. This I tested even though I was confident to be true.

Here is a very simple test script:
code:
Break on
$RC=WriteProfileString('C:\test.ini','Test','Name',@Fullname)

I ran it interactively with my domain account as well as a Scheduled Task. I also ran the Scheduled Task under various domain and local accounts.

Also, when the task is run in another user's context, it does not interact with the screen so there is no way you could see the @FullName macro results on the console.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#36859 - 2003-02-23 12:46 AM Re: Admin-related WriteValue Problem
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Okay, maybe I'm full of crap as well, but I'm not at work to test, and I don't use AT or SCHEDULER either one, so I was going on what I thought was happening.

Les and Palmer can work on it, I'll butt out now. [Wink]

Top
#36860 - 2003-02-23 12:56 AM Re: Admin-related WriteValue Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc, don't give up too easily.

I still think this is network issue, no matter what.
_________________________
!

download KiXnet

Top
#36861 - 2003-02-23 01:03 AM Re: Admin-related WriteValue Problem
bbpalmer Offline
Fresh Scripter

Registered: 2003-02-22
Posts: 6
Loc: New York City
I don't think I was giving you misinformation but I do think you hit the answer. As I was testing the code from a command line I was getting a response from @FullName, of course it wouldn't write to the registry because the account I was coding from didn't have permision. Then when I kicked off the task, it would write to the registry but @FullName would have given a null string. This fits the scenario perfectly.

I got around the problem by writing the user's Full name to a text file at the earliest stage of the login process. My scheduled KiX script then grabs that and all is well.

Thanks for all the help folks!

-Bruce

Top
#36862 - 2003-02-23 01:26 AM Re: Admin-related WriteValue Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dude, no problem!

any other problems we could help on?
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 756 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.071 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org