Solved

setting time under NT from non Administrator Accounting

Posted on 2000-03-09
16
203 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

743 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

10 Experts available now in Live!

Get 1:1 Help Now