|
-
Nov 18th, 2022, 05:26 PM
#1
Thread Starter
New Member
Setting the clock using VB6 - permissions and millisecond resolution
Running VB6 (SP6) under Windows 7. I'm logged in as an Administrator. I'm running the code using VB6 as a interpreter. I have not yet tried compiling anything, though that is the eventual goal.
I need a VB6 program which can read and write the system clock with a 0.1s precision.
I have found code which works just fine for reading the clock (https://home.wordpress.com/2010/04/0...-milliseconds/)
I don't fully understand how it works, but I can use it in my application without any problems. The problem I have with setting the clock is that, even just using something very simple like Date = "11/20/22" generates a runtime error 70 and a "permission denied" message. Ditto for statements like Time = "02:34:56". Permission error. Reading is fine. Setting is not.
I don't know what the code would be to set the time using the technique outlined for reading the time (presumably there's a SetSystemTime function, though I have no idea how to use it yet. Before I get into that, I want to make sure that it too won't fail due to a permission error. I have no idea what the interpreter (or complied code) runs as in terms of the permissions it has. I'm assuming if I'm an Administrator it runs with administrator permissions, but that may be (and certainly appears to be) a bad assumption!
So I have two questions - what do I need to do to make the simple Date = "11/20/22" work properly (i.e. what permissions to set/check?), and any tips on using SetSystemTime to set the time using milliseconds would also be appreciated.
Thanks
-
Nov 18th, 2022, 07:01 PM
#2
Re: Setting the clock using VB6 - permissions and millisecond resolution
The SYSTEMTIME type has ms.
You might need to enable SeSystemtimePrivilege and SeTimeZonePrivilege; admins have these permissions but they're disabled but default.
-
Nov 19th, 2022, 01:42 AM
#3
Thread Starter
New Member
Re: Setting the clock using VB6 - permissions and millisecond resolution
 Originally Posted by fafalone
The SYSTEMTIME type has ms.
You might need to enable SeSystemtimePrivilege and SeTimeZonePrivilege; admins have these permissions but they're disabled but default.
Would that affect the simple VB6 time and date setting functions? If I can't first get them to work I may have no hope doing anything more complex.
For example:
Code:
Private Sub Command1_Click()
Date = "10/20/22"
End Sub
This generates "run-time error 70, Permission denied" when the Command1 button is clicked, both when interpreted or compiled. Online guides and manuals make no reference to permissions. I know this error can occur if, for example, you try to access a file with the wrong permissions set, but I'm not trying to do that, I'm just using a function that's built into VB6 here, a simple Time or Date set.
-
Nov 19th, 2022, 01:59 AM
#4
Thread Starter
New Member
Re: Setting the clock using VB6 - permissions and millisecond resolution
OK. I think I have solved one problem. Looks like you need to launch VB6 with "run as administrator", not just "run". Probably obvious to experienced users, but not to me. That seems to allow the date and time to be set. Now I just have to figure out what's needed to set the time with a millisecond argument using SetSystemTime and SYSTEMTIME....
-
Nov 19th, 2022, 02:09 AM
#5
Re: Setting the clock using VB6 - permissions and millisecond resolution
 Originally Posted by bob046
Looks like you need to launch VB6 with "run as administrator", not just "run". Probably obvious to experienced users, but not to me.
This was part of the security lockdown that began in Windows Vista. Failure to do this and still try running VB6 can cause all sorts of problems to pile up and they can be difficult to reverse.
It was all explained in detail at great length in the developer information provided back in 2006. Almost nothing is left of those presentations and tutorials now on Microsoft sites. It isn't just VB6 related but has impacts on development using any language, even scripting.
For VB users this is just part of what "no longer supported for development" means. The responsibility for being aware of the issues and how to address them is yours.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|