|
Directory.CreateDirectory[^]
File.Copy[^]
Insert following into your main form to detect system shut down.
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0011)
{
}
base.WndProc(ref m);
}
www.troschuetz.de
-- modified at 3:40 Tuesday 30th August, 2005
|
|
|
|
|
Whether we can able to save all the open files automatically before the system shutdown.Also there exist any APIs for saving filet in c sharp.net.
I am expecting your most valuable reply
|
|
|
|
|
What do you mean by "all the open files"? What types of files do you open where and how?
www.troschuetz.de
|
|
|
|
|
I'm looking for way to capture audio (from microphone) and video (from webcam) and stream across network.. but most of examples that i have found are for web page web cam apps and thats not what i'm looking for. I came across one app example to capture webcam images but can't 'refind' the link.. and microphone capture eludes me.. I've been working on various aspects of this project for days now and could have easly passed them over by sheer exhaustion (coding can be an obsession).. any tips or pointers on simple audio/video device capture using p/invoke would forever indebted... Thank you for your time in reading my plea for help
When this darn code gets finished.. look for my article
|
|
|
|
|
Try this article:
http://www.codeproject.com/cs/media/directxcapture.asp
It is about Audio-Video capture in DirectX, and it is awesome!
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
How can I write superscript in label in winform. I need write l.s-1. How can I do this?
Thanks
My skills:
HTML - advance
PHP - advance
MySQL - advance
Perl and Embperl - beginner
C# - beginner
PostgreSQL - beginner
3D Studio - beginner
AutoCAD - profesional
Patrik Ružič
|
|
|
|
|
I don't believe you can, unless you owner draw. A label just uses one font, and fonts do not have the ability to superscript. You can put the number on the end in a smaller font, in a new label, or owner draw ( that is, write your own label class )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace shutdown
{
///
/// Summary description for Form1.
///
public class frmshutdown : System.Windows.Forms.Form
{
internal System.Windows.Forms.GroupBox grpQuestion;
internal System.Windows.Forms.Button btnDo;
internal System.Windows.Forms.RadioButton rdbLock;
internal System.Windows.Forms.RadioButton rdbLogoff;
internal System.Windows.Forms.RadioButton rdbRestart;
internal System.Windows.Forms.RadioButton rdbShutdown;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public frmshutdown()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.grpQuestion = new System.Windows.Forms.GroupBox();
this.btnDo = new System.Windows.Forms.Button();
this.rdbLock = new System.Windows.Forms.RadioButton();
this.rdbLogoff = new System.Windows.Forms.RadioButton();
this.rdbRestart = new System.Windows.Forms.RadioButton();
this.rdbShutdown = new System.Windows.Forms.RadioButton();
this.grpQuestion.SuspendLayout();
this.SuspendLayout();
//
// grpQuestion
//
this.grpQuestion.Controls.Add(this.btnDo);
this.grpQuestion.Controls.Add(this.rdbLock);
this.grpQuestion.Controls.Add(this.rdbLogoff);
this.grpQuestion.Controls.Add(this.rdbRestart);
this.grpQuestion.Controls.Add(this.rdbShutdown);
this.grpQuestion.Location = new System.Drawing.Point(26, 56);
this.grpQuestion.Name = "grpQuestion";
this.grpQuestion.Size = new System.Drawing.Size(240, 160);
this.grpQuestion.TabIndex = 1;
this.grpQuestion.TabStop = false;
this.grpQuestion.Text = "What do you want to do?";
//
// btnDo
//
this.btnDo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDo.Location = new System.Drawing.Point(160, 120);
this.btnDo.Name = "btnDo";
this.btnDo.Size = new System.Drawing.Size(64, 23);
this.btnDo.TabIndex = 5;
this.btnDo.Text = "Do";
this.btnDo.Click += new System.EventHandler(this.btnDo_Click);
//
// rdbLock
//
this.rdbLock.Location = new System.Drawing.Point(16, 120);
this.rdbLock.Name = "rdbLock";
this.rdbLock.Size = new System.Drawing.Size(128, 24);
this.rdbLock.TabIndex = 4;
this.rdbLock.Text = "Lock Computer";
//
// rdbLogoff
//
this.rdbLogoff.Location = new System.Drawing.Point(16, 88);
this.rdbLogoff.Name = "rdbLogoff";
this.rdbLogoff.Size = new System.Drawing.Size(128, 24);
this.rdbLogoff.TabIndex = 3;
this.rdbLogoff.Text = "Log off";
//
// rdbRestart
//
this.rdbRestart.Location = new System.Drawing.Point(16, 56);
this.rdbRestart.Name = "rdbRestart";
this.rdbRestart.Size = new System.Drawing.Size(128, 24);
this.rdbRestart.TabIndex = 2;
this.rdbRestart.Text = "Restart";
//
// rdbShutdown
//
this.rdbShutdown.Checked = true;
this.rdbShutdown.Location = new System.Drawing.Point(16, 24);
this.rdbShutdown.Name = "rdbShutdown";
this.rdbShutdown.Size = new System.Drawing.Size(128, 24);
this.rdbShutdown.TabIndex = 1;
this.rdbShutdown.TabStop = true;
this.rdbShutdown.Text = "Shutdown";
//
// frmshutdown
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.grpQuestion);
this.Name = "frmshutdown";
this.Text = "shutdown";
this.Load += new System.EventHandler(this.frmshutdown_Load);
this.grpQuestion.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new frmshutdown());
}
private void btnDo_Click(object sender, System.EventArgs e)
{
shutmode st=new shutmode();
if(rdbShutdown.Checked == true)
st.Shutdown(); //for shutdown
else if(rdbRestart.Checked == true)
st.Restart(); // Restart
else if(rdbLogoff.Checked == true)
st.LogOff(); //' Log off
else if(rdbLock.Checked ==true)
st.LockTheComputer();//' Lock Workstation
else
MessageBox.Show("Invalid option", "Illegal operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// ' Invalid Radio Button (should never been shown)
}
}
}
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
namespace shutdown
{
///
/// Summary description for shutmode.
///
public class shutmode
{
public shutmode()
{
//
// TODO: Add constructor logic here
//
}
// Constants
const int SE_PRIVILEGE_ENABLED=2;
const int TOKEN_QUERY=8;
const int TOKEN_ADJUST_PRIVILEGES=32;
const string SE_SHUTDOWN_NAME= "SeShutdownPrivilege";
//' Exit Windows Constant
const int EWX_LOGOFF = 0;
const int EWX_SHUTDOWN= 1;
const int EWX_REBOOT = 2;
const int EWX_FORCE = 4;
const int EWX_POWEROFF = 8;
const int EWX_FORCEIFHUNG= 16;
[StructLayout(LayoutKind.Sequential, Pack=1)]
//'Structure
internal struct Luid
{
public int Count;
public long luid;
public int Attr;
};
//End Structure 'TokPriv1Luid
//' Lock Workstation
[DllImport("user32.dll", ExactSpelling=true)]
static extern bool LockWorkStation();
//' Get Current Processes
[DllImport("kernel32.dll", ExactSpelling=true)]
static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", SetLastError=true)]
static extern bool OpenProcessToken(IntPtr h, int acc,IntPtr phtok);
//' Look up Priviledge Value
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern bool LookupPrivilegeValue(string host, string name,ref long luid) ;
// Adjust Token Priviledges
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, Luid newst, int len, IntPtr prev, IntPtr relen) ;
//' Exit Windows
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool ExitWindowsEx(int flg, int rea) ;
//' Exit Windows Sub
private void DoExitWindows(int flg)
{
Luid tp;
bool s;
int h1,h2;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, htok);
tp.Count = 1;
tp.luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
LookupPrivilegeValue(null, SE_SHUTDOWN_NAME,ref tp.luid);
AdjustTokenPrivileges(htok, false, tp, 0, IntPtr.Zero, IntPtr.Zero);
ExitWindowsEx(flg,0);
}
//' Shutdown
public void Shutdown()
{
DoExitWindows(EWX_SHUTDOWN);
}
// ' Restart
public void Restart()
{
DoExitWindows(EWX_REBOOT | EWX_FORCE);
}
//' Log off
public void LogOff()
{
DoExitWindows(EWX_LOGOFF);
}
//' Lock Workstation
public void LockTheComputer()
{
LockWorkStation();
}
}
}
-- modified at 1:46 Tuesday 30th August, 2005
|
|
|
|
|
It would help if instead of posting a million lines of code without comment, you told us what's wrong with it. Does it compile ? Does it do what you expect ? What do you expect ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This program is for shutdown,logoff,restart the system.
the pgm is compile without any error.
The problem is when we call the function ,for example shutdown ,the control is going to the ExitWindows()function.But its returned value is "0";so the shutdown command fails.i am unable to detect why the returned value is 0.
|
|
|
|
|
OK, that's a lot more helpful
So long as we're copying and pasting code, here's the code I found online to do this when I had the same problem as you. I think in a nutshell, some sort of privilege thing needs to happen first, which gives your app the *right* to shut down the PC.
public class Shutdown
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );
[DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea );
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;
private static void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
public static void ShutDown()
{
DoExitWin( EWX_POWEROFF | EWX_FORCE );
}
}
}
Christian Graus - Microsoft MVP - C++
-- modified at 2:02 Tuesday 30th August, 2005
|
|
|
|
|
First Thanks for helping me.
I am a new programmer.So i want to know what happend inside my program(means why i am getting the return value 0 from the Exitwindows()).Expecting the reason for that thing
|
|
|
|
|
I am using the FileStream class to write and read from files. I am using it in a server to which the clients can connect and read data from the file(s). The server, on the other hand is also writing data to the files after regular intervals of time. To write the data to the file, the server creates a FileStream object in the following way:
FileStream dataStream = new FileStream(dataFileName, FileMode.Open, FileAccess.Write);
As is clear from above, the server opens the file in write only mode and it shouldn't be a problem to read from the file.
To read data from the file, following code is used:
FileStream stream = new FileStream(fileNames[i].ToString(), FileMode.Open, FileAccess.Read);
As is clear here, I open the file in read-only mode. The problem is, that if the above code executes during the time when the server has already opened the stream for writing, I get an exception (Cannot access the file as it is being used by some other process).
Any help in this regard would be highly appreciated
|
|
|
|
|
No matter how logical it seems to you, Windows will not allow it, one process needs to release the file before another can access it. In the lack of deterministic destruction, that means the using keyword, or an explicit call to Close().
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks a lot Graus for your response, but still, is there any way out of this problem?
|
|
|
|
|
Tehnoon Raza wrote:
Thanks a lot Graus for your response,
No worries. I'm interested, why do so many people respond to me by my surname ?
Tehnoon Raza wrote:
is there any way out of this problem?
As far as I am aware, no.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No worries. I'm interested, why do so many people respond to me by my surname ?
Maybe they noticed that you are often grousing about Rent-a-coder in the lounge?
Matt Gerrans
|
|
|
|
|
Well, by default, the file is opened with Exclusive access. This means that all shared access, both read and write, is denied if another process tries to open the same file. This is actually a good thing in your situation.
If the server process is in the middle of writing to the file while your other process reads it, you could read an incomplete record or data or whatever. Your server process SHOULD hold an exclusive lock on that file when it needs to update it. What you can do, is when your other process needs to read the file, try and open it. If it's unavailable, just wait say five seconds, and try again. Keep doing that until you can finally open the file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
let's say i have:
string a="as";
string [] id;
how do i check whether string a is inside the array? so that it returns me a bool
|
|
|
|
|
Check if IndexOf returns -1.
---
b { font-weight: normal; }
|
|
|
|
|
hi friends
u can compair string using object.toString()
otherwise use string function to comapair
if(id[0].tostring()==s)
{
}
mukesh
|
|
|
|
|
I have created a windows service and I need for that service to run at 10:00 Am and 3:00PM every day.
I tried looking into the timer control but I could not figure out as to how can I schedule a Particular time of the day since the timer intervall starts when timer starts. Can someone please help me with this? Thanks in advance.
|
|
|
|
|
Check out this article: .NET Scheduled Timer[^] Follow the link to the latest source. I'm updating the article now so all the latest article updates should be in place in the next few days.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
|
Basically there are two ways you can follow:
Either you calculate the time to the next occurrence of the wanted action and wind up a timer with this interval or you set the interval to smaller time slices (for example, once a minute) and then check the current time if it's between 10:00:00 and 10:01:00 (or 15:00:00 and 15:01:00 resp.).
Regards,
mav
|
|
|
|
|