Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 19th, 2009, 04:34 PM
nglasson nglasson is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 2 nglasson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 11 sec
Reputation Power: 0
DOS Batch - Changing date to last year and back again

I am not sure if this is the right place to ask this question.

I am trying to come up with a way to read the current date, re-set the system date to have the year as 2008, run an application (then delay while the application loads) and then re-set the system date to make the year correct again.

I need to be able to do this in order to continue using a time limited CAD package called Pro Desktop Express. This program was a free trial but the software was discontinued 5 years ago. The last downloads were supplied with a 5 year serial code. Now we have a bundle of drawings that we can't open. I'm not looking to cheat the software vendor out of revenue because they don't offer a commercial version of Pro Desktop.

The expiry date on the software is easily bypassed by manually changing the date to last year before running the application. When the application is running, I can change it back to the correct date and the application still works fine.

I have got as far as a windows script to show the current date. I'm stumped as to how to go about running the application and then re-setting the date after a delay.

Can anyone help with an example.

Reply With Quote
  #2  
Old January 20th, 2009, 01:24 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,905 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 11 h 16 m 55 sec
Reputation Power: 969
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Ordinarily I do not reply to topics of this nature for obvious reasons. However, since the company no longer exists (and thus, neither does the user agreement) I'll help you out here.
vb Code:
Original - vb Code
  1. ' Connect to WMI with proper security permissions
  2. strComputer = "."
  3. Set objWMIService = GetObject("winmgmts:{(Systemtime)}\\" & strComputer & "\root\cimv2")
  4. Set colOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Primary=True")
  5.  
  6. For Each objOS In colOS
  7.     Exit For
  8. Next
  9.  
  10. ' Grab current date/time value
  11. strNow = objOS.LocalDateTime
  12.  
  13. ' Grab current year
  14. strYear = Left(strNow, 4)
  15.  
  16. ' Set date to 2008
  17. strDate = "2008" & Right(strNow, Len(strNow) - 4)
  18. objOS.SetDateTime strDate
  19.  
  20. ' Run your program here
  21. '
  22. '
  23. WScript.Echo "Check date"
  24. ' Repoll the current time value
  25. strNow = objOS.LocalDateTime
  26.  
  27. ' Reset the year
  28. strDate = strYear & Right(strNow, Len(strNow) - 4)
  29. objOS.SetDateTime strDate
Now, I'll try to explain a little how this works. It centers around the SetDateTime method which is part of WMI's Win32_OperatingSystem class. This class does require special permissions as you'll see shortly.
vb Code:
Original - vb Code
  1. ' Connect to WMI with proper security permissions
  2. strComputer = "."
  3. Set objWMIService = GetObject("winmgmts:{(Systemtime)}\\" & strComputer & "\root\cimv2")
  4. Set colOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Primary=True")
  5.  
  6. For Each objOS In colOS
  7.     Exit For
  8. Next
The script begins by connecting to the WMI service and querying for the current (assumed to be the primary) operating system. This query returns a collection containing a single object, but WMI collections don't support an Item method so there's no way to access a single object. To get around this, I used a For Each loop to iterate through the collection and exited the loop in the first iteration so that objOS contained the first (and in this case, only) item in the collection.
vb Code:
Original - vb Code
  1. ' Grab current date/time value
  2. strNow = objOS.LocalDateTime
  3.  
  4. ' Grab current year
  5. strYear = Left(strNow, 4)
  6.  
  7. ' Set date to 2008
  8. strDate = "2008" & Right(strNow, Len(strNow) - 4)
  9. objOS.SetDateTime strDate
In the next section of code, I begin by polling the LocalDateTime property for the current system date and time. WMI strings are in UTC format (specialized strings) so I'm using simple string manipulation to change the values. A current time might look something like this:
Code:
20090120141547.546000-300
As you can see, the first four characters in the string represent the year. The code above replaces those characters with "2008" and then assigns the new UTC value with the SetDateTime method.
vb Code:
Original - vb Code
  1. ' Run your program here
  2. '
  3. '
  4.  
At this point you should launch your program. I'd recommend using the WshShell object's Run method.
vb Code:
Original - vb Code
  1. ' Repoll the current time value
  2. strNow = objOS.LocalDateTime
  3.  
  4. ' Reset the year
  5. strDate = strYear & Right(strNow, Len(strNow) - 4)
  6. objOS.SetDateTime strDate
Finally, the date is reset. Notice that I'm polling the value again. Since the LocalDateTime property returns the current date and time, it's important not to use the value we captured earlier on. Otherwise, we'll end up losing time.
__________________
Don't like me? Click it.

Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!

Help us help you! Post your exact error message with these easy tips!

Reply With Quote
  #3  
Old January 20th, 2009, 02:15 PM
nglasson nglasson is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 2 nglasson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 11 sec
Reputation Power: 0
Thanks for the perfect answer

Thanks a bundle. That was the perfect answer to my problem. The user is happy because he no longer needs to manually change the date twice each day.

Reply With Quote
  #4  
Old January 20th, 2009, 03:33 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,905 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 11 h 16 m 55 sec
Reputation Power: 969
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Quote:
Originally Posted by nglasson
Thanks a bundle. That was the perfect answer to my problem. The user is happy because he no longer needs to manually change the date twice each day.
You're very welcome. I'm glad I could help out.

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > DOS Batch - Changing date to last year and back again


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek