I´m new to C# -- started three days ago because of an especific need regarding usb drives. Reading here and there I could have the following code to work. What I want is to know when an user inserts a pendrive in the usb port.
The only problem is the that on XP32 (the only XP I tested) the event will never be detected. On Windows 7 it runs perfectly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics;
using System.Threading;
using System.IO;
using Microsoft.Win32;
using System.Security.Permissions;
namespace X
{
class Program
{
static void Main(string[] args)
{
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2");
watcher.Query = query;
watcher.Start();
watcher.WaitForNextEvent();
// DO something if a pen drive (or any storage device) is inserted.
// Works fine on Windows 7
// XP will ignore the event...
}
}
}
Any suggestions will be very welcome!
Regards,
Sergio
Looks like you need XP service pack 3 for it to work (SP2 on x64).
Related
Trying to read the installation path of the game (InstallLocation) from one section in the registry (SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 4000), write it to another section (SOFTWARE\WpfApp) in key (NewInstallPath), and then find the exe file with the game in the installation path of the game, and run
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
namespace wpfApp
{
/// \<summary\>
/// Interaction logic for MainWindow.xaml
/// \</summary\>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
using var localMachineRegistry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
using var gmodAppRegistry = localMachineRegistry.OpenSubKey(#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 4000", false);
string readInstallPath = gmodAppRegistry.GetValue("InstallLocation").ToString();
RegistryKey InstallPath = Registry.LocalMachine.CreateSubKey(#"SOFTWARE\WpfApp", SetValue("NewInstallPath", readInstallPath)); //launcher partition path
}
}
}
As soon as I did not try to implement it, but even according to the documentation it comes out crooked. That value is recorded, but the game does not start, then nothing is recorded at all and does not start.
The way you're intended to run steam games is through steam itself.
Steam automatically updates the app etc.
There is a rungameid command line parameter which allows you to run a game ( somewhat ) directly.
"C:\Program Files (x86)\Steam\steam" steam://rungameid/281990
And... eventually as my login credentials install etc etc were stale...
Steam may be in C:\Program Files instead.
The nice-ish aspect of this is that you just need to check where steam is and know your game app id.
You can also run a game that isn't currently installed this way. There will of course be quite a delay as steam goes and gets everything for you.
I think some games are not so straight forward that they "just" have the one exe. Some have launchers ( ours does ).
I have been using Microsoft.Speech synthesizer for years on different PCs and different versions of Windows. I am trying to set up the development and support environment on a new Windows 10 PC and I can't get spsynthesizer to work correctly. I have downloaded the Microsoft SDK5.1 and the voices twice now to make sure nothing was corrupted. I have stepped through each line of code with the debugger and everything works as expected until the call to spsynthesizer.speak...the call never speaks and never returns to the program. I have tried executing as x86, x64 and AnyCPU and I have a reference entry to Microsoft.Speech.
Any suggestions? Here is the simple C# test application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Speech.Synthesis;
namespace test_text_to_speech
{
class Program
{
static void Main(string[] args)
{
Microsoft.Speech.Synthesis.SpeechSynthesizer spsynthesizer = new Microsoft.Speech.Synthesis.SpeechSynthesizer();
System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Speech.Synthesis.InstalledVoice> myvoices;
myvoices = spsynthesizer.GetInstalledVoices();
spsynthesizer.SelectVoice(myvoices[0].VoiceInfo.Name); //Invoke the one which you want
spsynthesizer.Volume = 100; // Can be 1 - 100
spsynthesizer.Rate = 1; // can be 1 - 10
spsynthesizer.SetOutputToDefaultAudioDevice();
PromptBuilder Thanks = new PromptBuilder();
Thanks.AppendSsmlMarkup("<voice xml:lang=\"en-US\">");
Thanks.StartStyle(new PromptStyle(PromptEmphasis.Strong));
Thanks.AppendText("Hello World");
Thanks.EndStyle();
Thanks.AppendSsmlMarkup("</voice>");
spsynthesizer.Speak(Thanks);
spsynthesizer.Speak("try with no markup");
}
}
}
I am recently working on a project for Serial port communication, I want to show the available serial ports in a comboBox, But while running it is not showing the available list of com ports.
My code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace Serial_application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
getPortsNames();
}
void getPortsNames()
{
string[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
}
}
}
There are no old style com ports on most modern computers, they are USB converters. If the USB device driver has not been installed there are no ports listed in the computer. Just solved this problem for myself.
I am using Android application with C# ,
My application involved
1-creating database and table
2 insertion-updation-deletion
3-Android 2.1
Application working perfectly in emulator , but after installing successfully in Tablet
i am getting this error during open the application while my tablet also have same android ver2.1.
Here is my some code i want know if something wrong in it ?
using System.Data;
using System.Collections.Generic;
using System.IO;
using Android.OS;
String Path_ = new databse.db().Database("netdobrasil.sqlite");
public string Database(string DbName)
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var pathToDatabase = Path.Combine(documents, "netdobrasil.sqlite").ToString();
SqliteConnection.CreateFile(pathToDatabase);
return pathToDatabase;
}
I'm working with some Audio files in my app (mp3, wav, ..etc)
I was using the Audio Class from the Microsoft.DirectX.AudioVideoPlayback dll
so first I had to download the dll, after doing so, I went to Add Reference
then I browsed to the dll location, and added it
I also installed the DirectX 9.0 Web Setup
Now, i don't get any problem with just saying: Audio aud;
but if I do something like this:
Audio aud = new Audio(path);
or
Video vid = new Video(path);
if I press Ctrl+F5 the app will crash immediately, If i try to debug, I just can't see the debugging cursor, and if i keep pressing F10 nothing ever happens ..
I put it in a try/catch block, it didn't threw an exception ..
so what's goin on ?
how can i fix this ?
I even tried to make a whole new app, here's the whole code, there's nothing really in it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
using Microsoft.DirectX.AudioVideoPlayback;
using Microsoft.DirectX;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Audio aud = new Audio("C:\\Users\\vexe\\Desktop\\Songs\\Kimosabe.mp3");
}
}
}
Any help would be appreciated ..
Thanks in advance ..
add this code to your project:
using Microsoft.DirectX.DirectSound
using Microsoft.DirectX