I have a program that i originally wrote in VB in SharpDevelop, it works perfectly in debug mode, and perfectly on my local machine. The only errors in the debugger are that some invalid options are sent to the compiler which i could easily delete from the build properties but cant be bothered to.
Now, the problem comes when running it on a remote machine. Let me explain... The purpose of this program is that it will be scheduled by Novell to run at about 8pm and probably again at 10pm on the local machine (so the machine receives the instruction then contacts the server's shared folder and executes the EXE file) the program itself then displays a window warning of imminent shutdown and a timer of about 30 mins, thats fine and works a treat, when the timer expires it is supposed to use the Shell() command to run "shutdown -s -t 0" and hence the machine is forcibly shutdown.
But it doesnt do it! I keep getting errors about the permissions being wrong, EG not high enough for the EXE to launch any other file/app/whatever
I ported it over to C# using the converter in the IDE program, just because i thought it would remove the dependency for the .net framework, alas it does not, however, i still get the same errors with the C# version RE permissions.
I dont code in VB or C but i do code in PHP so i have a good understanding of general programming, i also have a basic understanding of the permissions system in use here and that i need the system shutdown permission to use the built in C# shutdown function. I have copied code snippets left right and center and pasted them in, changed a few bits but not a single one has compiled properly, they all throw out critical errors before compiling fully and hence i cant even test them.
ITs doing my head in, can someone *please* help me with this. They are running on school computers so the students/staff cant be required to input anything or interact in any way other than to cancel the shutdown if they are still using the machine. The computers will all be on the network if that makes any difference and i am reluctant to use impersonation as an admin in case the rights somehow leak and give them admin access to things they shouldnt have access to.
My code is as follows:
CODE
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace timeout
{
public partial class MainForm
{
public MainForm()
{
// The Me.InitializeComponent call is required for Windows Forms designer support.
this.InitializeComponent();
timer1.Start();
timer_update.Start();
}
public void MainFormLoad(object sender, EventArgs e)
{
lbl_text.Text = "If you are currently using this computer click the button below and the shutdown will be aborted." + Constants.vbNewLine + Constants.vbNewLine + "This program will run periodically overnight to ensure electricity isnt wasted. Please ensure you save you work and shutdown all computers at the end of the day.";
}
public void Lbl_textClick(object sender, EventArgs e)
{
timer1.Stop();
System.Environment.Exit(0);
}
public void Button1Click(object sender, EventArgs e)
{
timer1.Stop();
System.Environment.Exit(0);
}
public void Timer1Tick(object sender, EventArgs e)
{
[b] timer1.Stop();
//Interaction.Shell("Shutdown /s /t 5");
//Process.Start("CMD.exe");
// Start the process.
Process.Start("notepad.exe");
System.Environment.Exit(0);
}
[/b]
public void Timer_updateTick(object sender, EventArgs e)
{
int time = 0;
string time_text = "";
time = timer1.Interval / 1000;
time = time / 60;
time_text = "" + time;
lbl_time.Text = time_text;
}
public void Lbl_timeClick(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace timeout
{
public partial class MainForm
{
public MainForm()
{
// The Me.InitializeComponent call is required for Windows Forms designer support.
this.InitializeComponent();
timer1.Start();
timer_update.Start();
}
public void MainFormLoad(object sender, EventArgs e)
{
lbl_text.Text = "If you are currently using this computer click the button below and the shutdown will be aborted." + Constants.vbNewLine + Constants.vbNewLine + "This program will run periodically overnight to ensure electricity isnt wasted. Please ensure you save you work and shutdown all computers at the end of the day.";
}
public void Lbl_textClick(object sender, EventArgs e)
{
timer1.Stop();
System.Environment.Exit(0);
}
public void Button1Click(object sender, EventArgs e)
{
timer1.Stop();
System.Environment.Exit(0);
}
public void Timer1Tick(object sender, EventArgs e)
{
[b] timer1.Stop();
//Interaction.Shell("Shutdown /s /t 5");
//Process.Start("CMD.exe");
// Start the process.
Process.Start("notepad.exe");
System.Environment.Exit(0);
}
[/b]
public void Timer_updateTick(object sender, EventArgs e)
{
int time = 0;
string time_text = "";
time = timer1.Interval / 1000;
time = time / 60;
time_text = "" + time;
lbl_time.Text = time_text;
}
public void Lbl_timeClick(object sender, EventArgs e)
{
}
}
}
I have bolded the section that deals with the timer expiration and what not, as you can see im making it launch notepad so i know its loaded rather than have my machine shut down everytime i want to test something....
I just cant get this to work, itd be really, really helpful if someone could write a little code for me, i know its being cheeky but if someone could write the code to give the right permissions i would be eternally grateful, either in VB or C# or at least help me out!!
Or if there is another way to shut the machine down then do tell! Ive tried the C# shutdown command with no luck, need the permissions again...

