473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Windows Services - Is there any code that can't be run in a servic

I need to check the state of a computer at boot time, and depending on that
state, launch an application before a user logs in. When the service starts,
it runs a batch file, which gets the state of the computer, and stores the
information in a registry key, then the service reads the key to determine
the state. If the state meets the correct parameters, the service checks to
see what the time is. The application can only run during a set amount of
time. If the time is correct (between 3 and 4 am) the application should
launch. The problem is, it doesn't seem to get to the point where it has
checked the time. It passes through the status check just fine, but never
returns from the time check. In fact, it never enters the time check. I
placed a console.beep in there so I could monitor the progress pre-login, and
it never beeps. Putting beeps in strategic locations up to this point come
out fine.

Here is the code for the OnStart method:
protected override void OnStart(string[] args)
{
SetfrzStateKey();//sets the key below
RegistryKey myKey =
Registry.LocalMachine.OpenSubKey("Software\\Educat ional Technology"
+ "\\LaunchPad", true);
String state = myKey.GetValue("frzstate").ToString();
#region Thawed/Frozen Check
if (state == "thawed")
{
Boolean TimeCheck = ChkTime();
if (TimeCheck == true)
{
Console.Beep();
StartLaunchpad();
}
else
{
return;
}
}
else if (state == "frozen")
{
return;
}
else return;
#endregion
}

Here are the supporting functions:
static bool ChkTime()
{
Console.Beep();
DateTime Now = DateTime.Now;
DateTime Today = DateTime.Today;
//if current time is after 3, but before 4, run updates
if (DateTime.Compare(Now, Today.AddHours(3)) > 0 &&
DateTime.Compare(Now, Today.AddHours(4)) < 0)
{
return true;
}
else return false;
}//end chktime
//===========================================
static void StartLaunchpad()
{
using (new Impersonator("Administrator", Environment.MachineName,
"myadminpassword"))
{
ManagementClass processClass = new ManagementClass("Win32_Process");
object[] methodArgs = { "c:\\slu_refresh\\lpupdater.exe /refresh",
"c:\\slu_refresh\\", null, 0 };
object result = processClass.InvokeMethod("Create", methodArgs);
}
}//end startlaunchpad method
//==================================================
static void SetfrzStateKey()
{
using (new Impersonator("Administrator", Environment.MachineName,
"myadminpassword"))
{
ManagementClass processClass = new ManagementClass("Win32_Process");
object[] methodArgs = { "c:\\slu_refresh\\dfc.bat",
"c:\\slu_refresh\\", null, 0 };
object result = processClass.InvokeMethod("Create", methodArgs);
ManagementObjectSearcher myQuery = new
ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE ProcessID = "
+ methodArgs[3]);
ManagementObjectCollection myCollection = myQuery.Get();
while (myCollection.Count > 0)
{
//While the batch file is running, wait
}
}//end Impersonation
}//end setrzstatekey
Apr 12 '06 #1
0 850

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
3
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I...
2
by: Vinoth Kumar | last post by:
hi all i wrote a windows service. i am trying to get it to use an app.config file. unfortunately, when the service starts, it assumes that the ConfigurationSettings file is in...
4
by: Jerry Camel | last post by:
I'm posting this here because it seems to be a much more active group that the standard VB group and I suspect that ASP developers may be more inclined to write a service, anyway. I've got my...
1
by: Tom | last post by:
I am writing a Windows service in VB.NET... I am using two applicatons - the actual service, and then an additional 'control app' (Windows Forms) that can be used to stop, start, monitor, etc the...
1
by: ian.johns | last post by:
I just need a simple code snippet to read from a config file the file locations needed for my Windows Service. Sort of like web.config but since this is a Windows Service, I won't be using that.
3
by: Matt Lowrance | last post by:
I'm hoping someone can give me a little guidance. I have written a simple Windows Service that goes out and scrapes a few web pages and updates some data in an access database. The service works...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: Overview NOTE- This complete article on "Windows Autorun FAQs" applies theoretically to all Windows NT-based OSes till Windows Vista (and probably Vista's successors too)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.