|
I've used System.ServiceProcess.ServiceController for this in the past.
For everything it's this:
using System.ServiceProcess;
private static void Devices() {
ServiceController[] scDevices = ServiceController.GetDevices();
Console.WriteLine("Device driver services on the local computer");
foreach (ServiceController scTemp in scDevices) {
Console.WriteLine("{0, -25} {1, -20} {2}",
scTemp.ServiceType, scTemp.ServiceName, scTemp.DisplayName);
}
}
And to hone in on a single target:
private static void SpecificService(String name){
try {
ServiceController sc = new ServiceController(name);
Console.WriteLine("{0, -25} {1, -20} {2}",
sc.ServiceType, sc.ServiceName, sc.DisplayName);
} catch (InvalidOperationException) {
Console.WriteLine(name + " service not found");
}
}
I have the Prolific driver installed, for which SpecificService("ser2pl") gives
KernelDriver ser2pl Prolific Serial port driver
Alan
|
|
|
|
|
Thanks for that I will give it ago! Mmmm is the boss watching it's nearly 5pm & I was in early.....
Glenn
Just tried it and get
Error 1 The type or namespace name 'ServiceProcess' does not exist in the namespace 'System' (are you missing an assembly reference?)
However I have the using System.ServiceProcess; which is not recognised by the intelisense however its late I'm off home more playing tomorrow.
Thanks Glenn!
|
|
|
|
|
Ah, I thought I'd catch you out with that! You'll need to add System.ServiceProcess to the project's references. It should be on the .NET tab of the Add Reference dialog.
Alan.
|
|
|
|
|
Yup you got me! Project -> Add System.ServiceProcess is good however it lists all the drivers time for some searching of the list!
|
|
|
|
|
hi every one
I'm really sorry if my question is quite simple
what I'm trying to reach is keycode.
that is in the code below:
foreach (System.Int32 i in Enum.GetValues(typeof(Keys)))
{
int x = KeyLogger.Methods.GetAsyncKeyState(i);
and then if any key is pressed i want to use MapVirtualKey to map and after all getkeynametext
to access to it's name.
what i'm trying to accessed is the keycode which I access to it's Enumvalues to use it in the code bellow
unit key=MapVirtualKey(m,MAPVK_VK_TO_VSC);
what i need here is M which is a virtualkeycode that i have it's enumvalues in i;
thank you all in advance for helping me.
|
|
|
|
|
as mention in the subject,
im currently trying to do a system that can scan the network and list out all the actives computer within the domain network.
i check some of the sample project in this website,
but the link are dead..
|
|
|
|
|
|
I am developing a specialized search system for SQL server data. Nightly I consolidate information from a number of tables into one “SourcingPool”. I have enabled full-text searching on this table and experimented with freetext, contains, etc. I have the web display and can search for single words.
Now I need a way to take a Google like string and dismember it into search strings I can use in SQL server commands. I would like to be able to handle and, or, not, quoted strings, etc.
Does anyone have example code for this?
|
|
|
|
|
First, how exactly are you performing the search now? Let's see a code snippet.
You might want to read this[^] first.
|
|
|
|
|
At the moment I have the operator input a search string and pass it to a stored procedure in SQL server. The filtering is done with freetext.
select P.co_name
,P.add_city
,P.ProvinceCode
,case when Co.UseCodeAsName = 1
then Co.CountryCode
else Co.CountryName end as CountryName
,isnull(DATEDIFF(month, P.profile_date, getdate()), 999) as proMonths
,P.proServices
,P.proRegions
,P.p_key
,P.co_status as coStatus
,P.PostalCode
,case
when P.PostalCode is null
then null
else sqrt(square(sin((ZZ.LatitudeInRadians-@TestLatRadians)/2.0E)) +
(cos(@TestLatRadians) * cos(ZZ.LatitudeInRadians) * square(sin((ZZ.LongitudeInRadians-@TestLongRadians)/2.0E))) )
end
as dist_base
from dbo.SourcingPool as P
left outer join dbo.defProvince as Pr
on P.ProvinceCode = Pr.ProvinceCode
and P.CountryCode = Pr.CountryCode
left outer join dbo.defCountry as Co
on P.CountryCode = Co.CountryCode
left outer join dbo.defPostalCodes as ZZ
on ZZ.PostalCode = P.PostalCode
where (freetext(P.*, @SearchString) or CHARINDEX(@SearchString, P.proServices) > 0)
|
|
|
|
|
You could consider using Regular Expressions for this kind of text search.
Here[^] is a good msdn article on this approach.
|
|
|
|
|
I need to make a multilingual virtual keyboard. It should have support for accented characters like â, ƒ etc.
Normally we make such characters by pressing alt key, typing a sequence on numpad (e.g. 131) and releasing alt key. It works with manual input, but i am not able to simulate such action from input simulator.
I took logic from http://inputsimulator.codeplex. I have tried SimulateModifiedKeystoke, extended key board patch given by you, tried adding some delay, tried code in http://inputsimulator.codeplex.com/discussions/235928 . But nothing seems to be fixing this.
This is what i am trying :
List<VirtualKeyCode> myList = new List<VirtualKeyCode>();
myList.Add(VirtualKeyCode.NUMPAD1);
myList.Add(VirtualKeyCode.NUMPAD3);
myList.Add(VirtualKeyCode.NUMPAD1);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.MENU, myList);
public static void SimulateModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable<VirtualKeyCode> keyCodes)
{
SimulateKeyDown(modifierKey);
if (keyCodes != null) keyCodes.ToList().ForEach(x => SimulateKeyPress(x));
SimulateKeyUp(modifierKey);
}
public static void SimulateKeyPress(VirtualKeyCode keyCode)
{
bool isExtendedKey = InputSimulator.IsExtendedKey(keyCode);
uint KEYEVENTF_EXTENDEDKEY = 0x0001;
uint KEYEVENTF_KEYUP = 0x0002;
var down = new INPUT();
down.Type = (UInt32)InputType.KEYBOARD;
down.Data.Keyboard = new KEYBDINPUT();
down.Data.Keyboard.Vk = (UInt16)keyCode;
down.Data.Keyboard.Scan = 0;
down.Data.Keyboard.Flags = 0;
down.Data.Keyboard.Time = 0;
down.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY;
down.Data.Keyboard.ExtraInfo = IntPtr.Zero;
if (isExtendedKey)
{
down.Data.Keyboard.Flags = (UInt32)KeyboardFlag.EXTENDEDKEY;
}
var up = new INPUT();
up.Type = (UInt32)InputType.KEYBOARD;
up.Data.Keyboard = new KEYBDINPUT();
up.Data.Keyboard.Vk = (UInt16)keyCode;
up.Data.Keyboard.Scan = 0;
up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP;
up.Data.Keyboard.Time = 0;
up.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
up.Data.Keyboard.ExtraInfo = IntPtr.Zero;
if (isExtendedKey)
{
up.Data.Keyboard.Flags = up.Data.Keyboard.Flags | (UInt32)KeyboardFlag.EXTENDEDKEY;
}
INPUT[] inputList = new INPUT[2];
inputList[0] = down;
inputList[1] = up;
var numberOfSuccessfulSimulatedInputs = SendInput(2, inputList, Marshal.SizeOf(typeof(INPUT)));
if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode));
}
|
|
|
|
|
revengeoffallen wrote: I have tried SimulateModifiedKeystoke, extended key board patch given by you
To whom are you addressing this? If this is referring to some article here on CodeProject then you should post your query in the forum at the end of the article.
|
|
|
|
|
I am not referring to any specific article on code project. I am referring to virtual key boards and virtual key code logic in general.
|
|
|
|
|
revengeoffallen wrote (in original post): extended key board patch given by you
I was asking who you mean by "you"?
|
|
|
|
|
I am using Telerik controls 2012 Q2 Net35 trial version in my project,am getting xaml parser exception 'Set connectionId threw an exception.Line number 9 and line position 9', when i run the project.
am getting the error here
<Window x:Class="PVAccelerator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:PVAccelerator.Models"
Title=" " Icon="/Images/photovault.ico" Height="325" Width="525" WindowStyle="SingleBorderWindow" WindowState="Normal" ResizeMode="CanResize" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Loaded="Window_Loaded" Closing="Window_Closing"
xmlns:Telerik_Windows_Controls_RibbonBar_Primitives="clr-namespace:Telerik.Windows.Controls.RibbonBar.Primitives;assembly=Telerik.Windows.Controls.RibbonBar"
xmlns ="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna">
<Window.Resources>
-- modified 26-Jun-12 2:00am.
|
|
|
|
|
Why are you asking this here?? It's a question specific to Teleriks controls. Ask them about it, here[^].
|
|
|
|
|
need to do a console application that shows arabic numerals next to their roman counter part. I'm lost on the conversion part getting it into another method and how that works? Just need to know where to start.
|
|
|
|
|
That is best broken into two parts:
0) Parsing the arabic numerals into a variable -- for which you may want to use System.Int32.TryParse .
1) Converting the value to Roman numerals.
The following will convert the value 42 into Roman numerals:
new System.String ( 'I' , 42 )
Compressing the value is left as an exercise.
|
|
|
|
|
thanks for the help but i guess now the problems is looping it so that they show counting down this is what i have.
namespace ConsoleApplication1
{
class Program
{
public static string ToRoman(int i)
{
if (i <= 0) return "";
int[] Nums = { 1 , 4 , 5 , 9 , 10 , 40 ,
50, 90 , 100, 400, 500, 900, 1000};
string[] RomanNums = {"I", "IV", "V", "IX", "X", "Xl",
"l", "XC", "C", "CD", "D", "CM", "M"};
string sRtn = ""; int k = i;
for (int j = Nums.Length - 1; j >= 0; --j)
{
while (k >= Nums[j])
{
k -= Nums[j];
sRtn += RomanNums[k];
}
}
return sRtn;
}
static void Main(string[] args)
{
for( int Nums = 1; Nums <= 4000; Nums++)
{
Console.WriteLine(Nums + RomanNums[]);
}
|
|
|
|
|
Salomon Velazquez wrote: sRtn += RomanNums[k];
May I suggest a System.Text.StringBuilder instead?
You don't need k .
How about using an array of Tuple<int,string> rather than two arrays? And make it a static readonly field.
The for loop ought to stop when the value reaches zero, then you can eliminate the first if statement.
Your code won't produce MIM for 1999.
|
|
|
|
|
Private Sub UpdateSecurityStatus(ByRef device As deviceStruct, ByVal w128 As Int16)
device.ATAdeviceInfo.MasterPasswordCapabilty = (w128 >> 8) And 1
device.ATAdeviceInfo.EnhancedSecurityErase = (w128 >> 5) And 1
device.ATAdeviceInfo.SecurityCountExpired = (w128 >> 4) And 1
device.ATAdeviceInfo.SecurityFrozen = (w128 >> 3) And 1
device.ATAdeviceInfo.SecuirtyLocked = (w128 >> 2) And 1
device.ATAdeviceInfo.SecurityEnabled = (w128 >> 1) And 1
device.ATAdeviceInfo.SecuritySupported = w128 And 1
End Sub
w128 = 41 when this is called.
What it the '>>' and what does the 'And 1' mean. How do I write this in C#?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The VB.NET expression:
(w128 >> 8) And 1
means, shift the value of variable w128 right 8 bits and then AND the resulting value with 1. Thus if w128 contains the binary value 0101100100 the result would be 1. In C# you would write this as:
(w128 >> 8) & 1
So these expressions are just matching certain bits in the w128 variable and using them to set flags in device.ATAdeviceInfo .
[edit]
See here[^] for information on VB.NET operators.
[/edit]
|
|
|
|
|
Ahh ok. Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The full conversion is:
private void UpdateSecurityStatus(ref deviceStruct device, Int16 w128)
{
device.ATAdeviceInfo.MasterPasswordCapabilty = (w128 >> 8) & 1;
device.ATAdeviceInfo.EnhancedSecurityErase = (w128 >> 5) & 1;
device.ATAdeviceInfo.SecurityCountExpired = (w128 >> 4) & 1;
device.ATAdeviceInfo.SecurityFrozen = (w128 >> 3) & 1;
device.ATAdeviceInfo.SecuirtyLocked = (w128 >> 2) & 1;
device.ATAdeviceInfo.SecurityEnabled = (w128 >> 1) & 1;
device.ATAdeviceInfo.SecuritySupported = w128 & 1;
}
If you have conversions to do just go here: http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] - it's a free online Vb to C# and vice versa converter. I used it for teh above, and use it for answering VB questions in QA. It's not perfect, but it gets a good percentage of it done. If it compiles in VS, it will probably convert automatically.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|