I'm fighting here with System.Printing namespace of .net framework.
And what i always saw as a wired thing in all the tools by MS to manage my printservers is they lack Port and Driver managing functionality.
So I'm stuck here with a piece of code that works:
PrintServer _ps = new PrintServer(PServer,
PrintSystemDesiredAccess.AdministrateServer );
_ps.InstallPrintQueue(QToCreate.Name, QToCreate.Driver,new string [] {"LPT1:"}, "winprint", PrintQueueAttributes.None);
And it does create a Queue for me on remote server, using the driver i specify, but driver should be there on server already which i can live with, but i failed to find a way to create new TCP/IP port on my print server, so installing new print queues this way can be something usable. i don't see why am i allowed to only install new queues with existing ports. kinda fails me. If somebody knows how to create a port along with a queue, i'd like to see how.
gah.. and when there is no hope - do research more
short answer - "you can't add a port using system.printing"
long answer - use wmi
vb sample follows:
Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
' Use IP of Printer or Machine sharing printer
objNewPort.Name = "IP_192.168.1.1"
objNewPort.Protocol = 1
objNewPort.HostAddress = "192.168.1.1"
' Enter Port number you would like to use
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_
Related
I'm trying to understand how I might access the RSSI of a Bluetooth (not LE) connection in either C# or C++ on Windows.
My understanding is that there is no straightforward "GetRSSI()" type command but is there any indirect way to access it?
Everything I've found so far seems to be aimed at LE connections.
Edit:
I've had a look into AEPs and tried to get the SignalStrength AEP from a connected BT device.
foreach (var key in deviceInformation.Properties.Keys)
{
Debug.WriteLine($"{key}: {deviceInformation.Properties.GetValueOrDefault(key)}");
}
Gives:
System.ItemNameDisplay: <ommitted>
System.Devices.DeviceInstanceId:
System.Devices.Icon: C:\Windows\System32\DDORes.dll,-2001
System.Devices.GlyphIcon: C:\Windows\System32\DDORes.dll,-3001
System.Devices.InterfaceEnabled:
System.Devices.IsDefault:
System.Devices.PhysicalDeviceLocation:
System.Devices.ContainerId:
With the item name omitted by me.
So it looks like there are no AEPs, unless I'm missing something?
I know this is late, but I just started a new project where I also want information about the SignalStrength for Bluetooth (not LE) devices.
#Mike-Petrichenko was giving you some good hints. After following his advice of searching for "System.Devices.Aep.SignalStrength" I found this post
After going throw the OPs Code and debugging a little, I came up with this solution:
private const string SignalStrengthProperty = "System.Devices.Aep.SignalStrength";
var additionalProperties = new[] { SignalStrengthProperty };
DeviceWatcher mWatcher = DeviceInformation.CreateWatcher(BluetoothDevice.GetDeviceSelector(), additionalProperties);
var rssi = Convert.ToInt16(deviceInformation.Properties[SignalStrengthProperty]);
I'm currently doing an assignment where I want my program to be able to read and update a database. The database itself runs on oracle and was provided by my university (I have my own schema I believe?)
Right now I can connect via SSH using programs such as teraterm or putty, once I log in it takes me to an interactive menu which allows me to select a few various options. One of which is shell. Once I select that I am able to use bash commands to log into the SQL section and use these:
bash$ export ORACLE_HOME=/opt/oracle/product/client/11.2.0
bash$ export TWO_TASK=SSID
bash$ $ORACLE_HOME/bin/sqlplus
to connect to the SQL database. Easy.
However, I want to be able to do that through my program and it is proving difficult for me. I am using SSH.NET and can connect via SSH seemingly well. The problem is I cannot access the SQL section. When I run the commands the first two work correctly I believe, but the last one does not. It seems to not be able to see the anything past $ORACLE_HOME. When I "echo $ORACLE_HOME /*" it even tells me that /bin is a folder:
/bin /boot /dev /etc /export /hey.php /home /lib /lib64 /local /lost+found /media /misc
/mnt /opt /proc /root /sbin /selinux /srv /stage /sys /tmp /usr /var
But instead, when I run the last line of code I get the error message:
Error = "bash: /bin/sqlplus: No such file or directory\n"
I'm not sure whether there is an easier way of accessing the SQL stuff... But I am very close using SSH.NET but I just can't see why I can't open the SQL section like I can in putty or teraterm...
Any help would be greatly appreciated, thank you for your time.
My actual C# code is this:
//Connection information
string user = "SSHusername";
string pass = "password";
string host = "address";
//Set up the SSH connection
using (var client = new SshClient(host, user, pass))
{
//Start the connection
client.Connect();
var output = client.RunCommand("export ORACLE_HOME=/opt/oracle/product/client/11.2.0");
Console.WriteLine(output.Result);
output = client.RunCommand("export TWO_TASK=SSID");
Console.WriteLine(output.Result);
output = client.RunCommand("$ORACLE_HOME/bin/sqlplus");
Console.WriteLine(output.Result);
output = client.RunCommand("username");
Console.WriteLine(output.Result);
output = client.RunCommand("password");
Console.WriteLine(output.Result);
output = client.RunCommand("SELECT * FROM users;");
Console.WriteLine(output.Result);
client.Disconnect();
Console.WriteLine(output.Result);
}
1.I suggest you use native C# package for connect Oracle. You will get wrong format of output.
I see your variable is not work. Because SQLPLUS client should be under
$ORACLE_HOME/bin/sqlplus. But your code show /bin/sqlplus. Means $ORACE_HOME not work.
You can directly change code and run directly sqlplus like /opt/oracle/product/client/11.2.0/bin/sqlplus user/pass#SSID
You can set some script on remote oracle server and get result over that or upload script from C# host to remote each time.
If you're using the SSH.NET library, using a Shell instead of separate Commands should work - something like (untested):
using (var client = new SshClient(host, user, pass)) {
client.Connect();
client.CreateCommand("export ORACLE_HOME=/opt/oracle/product/client/11.2.0").Execute();
client.CreateCommand("export TWO_TASK=SSID").Execute();
client.CreateCommand("$ORACLE_HOME/bin/sqlplus").Execute());
...
client.Disconnect();
}
Original source code found at SSH.NET example
ok folks i have seen alot of questions about this but none that i can use or understand
What i am attempting to do is connect to putty from asp.net c# and then run a command to get the status
i will then use the results to draw a report every 3 seconds and display it on my web page
this is the first time a have attempted this so i am rather ignorant
private void connect_putty()
{
Process sh = new Process();
sh.StartInfo.FileName = "Putty.exe";
sh.StartInfo.UseShellExecute = false;
sh.StartInfo.CreateNoWindow = false;
sh.StartInfo.Arguments = "";
}
what i presently have which to be honest is pathetic any help will be appreciated
Thanks in advance
I would suggest using Tamir.SSH.
This will allow you to do everything from C#.
Also, I wrote some code once, it may help you.
https://github.com/daneb/Push2Linux/blob/master/Form1.cs
Sample:
SshShell ssh; // create our shell
ssh = new SshShell(aHost.host, aHost.username, aHost.password);
// Command Output
string commandoutput = string.Empty;
// Remove Terminal Emulation Characters
ssh.RemoveTerminalEmulationCharacters = true;
// Connect to the remote server
ssh.Connect();
//Specify the character that denotes the end of response
commandoutput = ssh.Expect(promptRegex);
PuTTY includes all the terminal emulation (hence the name), so assuming you mean 'connect via ssh', instead of the putty app specifically, then SSH.NET and SharpSSH are 2 good choices.
See this related question: C# send a simple SSH command
A line similar to the following threw the above exception:
PrintServer ps = new PrintServer(#"\\prntsrv");
When I use "Run..." on Windows the address above does work and take me to the list of print jobs so why does the line of code not work?
Apparently, the address \\prntsrv was a DNS alias to \\prntserv and the PrintServer constructor was unable to deal with it. To get around this issue I used the following code (I could also use just the code in the catch block instead and it would work, but preferred not to):
try
{
// Create object to monitor the printer queue
PrintServer printServer = new PrintServer(serverPath);
mPrintQueue = printServer.GetPrintQueue(printerName);
}
catch (PrintServerException ex)
{
// If the problem might be creating the server because the name is an alias
if (ex.Message.Contains("printer name is invalid."))
{
string actualServerHostname = "\\\\" + Dns.GetHostEntry(serverPath.TrimStart('\\')).HostName;
// Create object to monitor the printer queue
PrintServer printServer = new PrintServer(actualServerHostname);
mPrintQueue = printServer.GetPrintQueue(printerName);
// Write to log about the use of a different address
}
else
{
throw;
}
}
hey i was facing similar issue, this is what i observed and made following changes, just try and let me know.
This issue was occuring due to windows feature/role "Print and Document service" is missing on the system. This role is required for managing multiple printers or print servers and migrating printers to and from other windows servers.
To add the role Go To Control Panel->Turn windows feature on or off->click on check box "Print and Document Service"->install.
See with network administrator for installing this rule if you unable to add it.
After adding the role you can able to create print server object and get the all the printqueues on respective server.
I want to be able to specify how many clients do I want opened, and be able to manually switch between the windows after they're opened- meaning "streaming in background" (if such a thing is possible? ) won't do here.
I need to specify different inputs for the different clients as well.
Additionally -and this is the part I'm totally clueless about as it's VLC-specific - I need the clients to be logging some info re:the stream they're receiving, so as to be able to determine that it has been received completely etc -such as frame rate/total frames' number or similar.
I'd appreciate helpful suggestions for
running the instances+ controlling
them
getting info about
the stream
Language-wise - I know Java, some C#, and wouldn't mind learning some new language for this purpose if it's a better solution .
Thanks!
Depending on your version of VLC, you may need to enable an option to run multiple instances. See here: http://wiki.videolan.org/How_to_play_multiple_instances_of_VLC
It does sound like a 'run windows processes in a loop' thing, which you could do several ways.
You could make a windows batch file (.bat):
"C:\path\to\vlc.exe" -vvv "http://www.whatever.com/mystream.mms"
"C:\path\to\vlc.exe" -vvv "http://www.whatever.com/mystream2.mms"
"C:\path\to\vlc.exe" -vvv "C:\music\whatever.mp3"
Or you could use a real programming language and perhaps open a variable number of instances... C# for example:
using System.Diagnostics;
...
foreach (string stream in streamList) {
Process myProc = new Process();
string myCmd = #"C:\path\to\vlc.exe";
string myArgs = "-vvv \"" + stream + "\"";
ProcessStartInfo myStart = new ProcessStartInfo(myCmd, myArgs);
myStart.UseShellExecute = false;
myProc.StartInfo = myStart;
myProc.Start();
}
See this page for a full list of VLC command line options: http://www.videolan.org/doc/vlc-user-guide/en/ch04.html
Hope this helps.
You'll either need to run several processes (as above) or hook somehow into libvlc and instruct it to start up several players.
A good demo of this is the python wrapper to libvlc--I think--it shows how to sample to know where the stream is--however I've never tried it with multiple things running at the same time but I think it would work.
Another option might be something like http://wiki.videolan.org/Mosaic