Solved

setting time under NT from non Administrator Accounting

Posted on 2000-03-09
16
204 Views
Last Modified: 2010-04-15
i need to set the sistem time without using NT Security (because my program will run on NT under non Admin login and it must have the possibility to set the system time!)

how can i do this?
and it's possible to do it?
(samples of source code are needed)

thanks

Cristian Bertoldi

i've posted the question under C++ section too. I will assign 500 points to the first correct answer.....
0
Comment
Question by:crisbert
  • 8
  • 8
16 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 500 total points
ID: 2600462
The SetSystemTime() function is the only way to set the time on an NT system.  Unfortunately for your situation, this is a privileged function and, as the SDK says, the account calling it must have the SE_SYSTEMTIME_NAME (a.k.a "Change the system time" in the User Manager)

You have two options:

1) Assign this privilege to the user account(s) in question so that your program can request this privilege (using the AdjustTokenPrivileges call) when it needs to set the time.

2) Implement an NT service which runs under the Local System account to modify the system time on your program's behalf.

There are no shortcuts here since we are dealing with Windows NT security.  If things like this were able to be easily hacked, NT security would be useless.

I'll be happy to post some source code for either one of the above options if they make sense for your situation.  Of course, there are drawbacks to either one.

Giving the user(s) the privilege might not be possible since you may need to run/install this application on a system where you cannot give users this privilege.

Installing a server must be done using an administrative account and again, this might not be possible in your situation.  
0
 

Author Comment

by:crisbert
ID: 2601720
i can't give the admin login to the user, so i'll try to create a service if you send me a sample....

thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 2601797
I'll have that for you shortly.

0
 
LVL 32

Expert Comment

by:jhance
ID: 2602035
OK, here you go...

Please download:

ftp://www.jwhance.com/pub/TimeSetSvc.zip

This VC++ Workspace has 2 projects in it:

1) TimeSvc.  This is an NT service project that permits setting the time from a user application.  Compile it and then install the service from a command prompt:

TimeSvc -install

This will install but will not start the service.  Open the Services Control Panel and start the service. NOTE: You must be administrator to install a service.  Once this starts running you should hear an annoying beeping to let you know it's working.

2) TimeSetClient.  A Windows GUI application that when started, reads the current time.  If you change the time in the window and click OK, it will transact with the service and change the time.  If it "takes" you will hear a different (i.e. lower) beep.  It it fails (like from getting an invalid time input) the service will make a high-pitched beep.

This GUI app can be run by anyone.

WARNING:  Little attempt has been made to ensure graceful handling of errors and no consideration has been given to security.  In other words, please take time to understand what this thing is doing and how it might be abused by a hostile user.

Please let me know if you have any questions.
0
 

Author Comment

by:crisbert
ID: 2603765
OK, can i set the system time with this service from a visual basic application??? (the vb project get the date from an OS/390 Host and pass it to the service that.....)


(if this is not possible i'll try to get the Host's date from this service.)

thanks

For some strange reason (proxy or i don't know ...) i can't download your sample. May you send it at the address bertoldi.cristian@libero.it

Thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 2604060
I've gone ahead and sent it to you at your email address.

>OK, can i set the system time with
>this service from a visual basic
>application??? (the vb project get the
>date from an OS/390 Host and pass it
>to the service that.....)

Yes, of course.  This sample uses a Windows NT named pipe to communicate with the server which can be done from a VB application.  Of course, there are any number of other communication methods that could be used as well.

0
 

Author Comment

by:crisbert
ID: 2604067
this is the correct solution for my problem; i'll compile the sample that you gave to me cutting visual reference for make a DLL (for vb calling)

i can't still download the sample (can't access to ftp site....)

can you send it to bertoldi.cristian@libero.it or bertoldi.cristian@tiscalinet.it ?

thanks for your patience.

crisbert
0
 

Author Comment

by:crisbert
ID: 2604073
excuse me, if I've asked twice times to send me the files...

i've received all...
now i'm testing...

wait a little time and i'll give you your points.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:crisbert
ID: 2604144
it worked!!!!

thanks for all.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2604214
Let me know if you need any help talking to the service using VB as a client.  I'm not a VB guru but it's pretty straightforward.  The biggest trick is calling Windows API functions from the VB application.  Once you know how to do that, the process is virtually identical to the VC++ client program.

(I still can't figure out why you cannot connect to the FTP site....)
0
 

Author Comment

by:crisbert
ID: 2604247
if i log in with an userid of the USER NT's Group, the settime client app stop when it try to connect to the pipe... Why?

(I hear a double thick)

0
 
LVL 32

Expert Comment

by:jhance
ID: 2604360
>USER NT's Group

I don't understand what you mean by this.

Where is the client app stopping?  Run it in the debugger.

The only place where I see a potential problem is at the ConnectNamedPipe() call.  You might modify it to read:

      if(hPipe == INVALID_HANDLE_VALUE){
            AfxMessageBox("Error in CreateNamedPipe", MB_OK);
            return;
      }
      else{
            if(ConnectNamedPipe(hPipe, NULL)){
                  DWORD dwBytesWritten;
                  WriteFile(hPipe, (LPCVOID)&t, sizeof(SYSTEMTIME), &dwBytesWritten, NULL);
            }
            else{
                  AfxMessageBox("Error in ConnectNamedPipe", MB_OK);
            }
            CloseHandle(hPipe);
      }

This shouldn't fail unless the pipe has been closed by the service.
0
 

Author Comment

by:crisbert
ID: 2604377
excuse me, when i've installed the service i set to it an other acconnt!

now i've edited and set the sistem account and it work!

i'm testing the vb code, i'll send you a sample if you want...

Thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 2604507
>excuse me, when i've installed the service i set to it an other acconnt!

You probably want to leave it as the Local System account.  Unless there is a good reason for setting it to another user, this wastes system resources as NT must create an "NT Window Station" for every user on the system, including those running as services.  This consumes resources.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2610189
Just in case anyone is interested in downloading this code, I've put it somewhere else where it should be more accessible:


http://www.jwhance.elosoft.com/TimeSetSvc.zip
0
 

Author Comment

by:crisbert
ID: 2611967
thanks jhance,
it work perfectly under VB6 (i've found some trouble setting the pointer to the security structure in CREATENAMEDPIPE, but nothing unresolvable....)

now i can set the sistem time from my VB & C programs directly....

if someone is intrested in the vb code please aksit to me at bertoldi.cristian@libero.it


0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pgpool-II on Ubuntu 14.04... ARGH! 5 846
Parsing XML instructions in Java/any other language.... 3 104
sameEnds challenge 3 135
IIS Log files on Exchange 2013 server 6 84
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now