I want to change MTU value for windows 7/8.1/10 with C#.
I tried to search on Stack Overflow but only netsh is what I can find.
Get current MTU value
Set custom MTU value
I don't want to use any cmd commands, any idea to do with C# only?
You should be able to use the WMI API for this.
There's a Visual Basic example you can probably adapt:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetMTU(68)
The SetMTU method is documented here, and the C# APIs to talk with WMI are documented here.
Related
We are currently developing an addin that interact with the end user visually to give some informations, and we wanted to use Mailtips but apparently it is not possible from what we saw
Nevertheless, is it possible to have something similar or to mimic this kind of tip (2nd sshot would be ideal)..
Option 1:
https://i.stack.imgur.com/vcQYb.png
Option 2:
https://i.stack.imgur.com/7k19w.png
We also looked and form region but that would be the last option, ideal would be to have the tooltip in 2nd screenshot to display a small message to help user (any clue appreciated).
We were also looking for a function to disable links in the body (as the junk filter does), but also no chance finding this through the documentation (maybe internal procedure)
Looking everywhere for documented elements...
On the screenshot you have seen a standard Outlook notification and MailTips - that is a feature of Exchange, not Outlook.
We also looked and form region but that would be the last option, ideal would be to have the tooltip in 2nd screenshot to display a small message to help user (any clue appreciated).
The Outlook object model doesn't provide anything for that, there is no built-in property or method for that. The only possible option is to use a form region where you could put your custom UI at the bottom of the standard form/window in Outlook. The Adjoining layout available for Outlook form regions appends the form region to the bottom of an Outlook form's default page. So, if you want to place the form at the top you need to use Windows API functions to subclass Outlook windows or consider using the Advanced Outlook view and form regions where the top layout is provided out of the box.
Also you may consider developing a web add-in for Outlook where you could set up notification items programmatically from the add-in, see Office.NotificationMessages interface for more information. For example:
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml
const id = $("#notificationId").val();
const details =
{
type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
message: "Non-persistent informational notification message with id = " + id,
icon: "icon1",
persistent: false
};
Office.context.mailbox.item.notificationMessages.addAsync(id, details, handleResult);
See Build your first Outlook add-in to get started quickly on that.
We were also looking for a function to disable links in the body (as the junk filter does), but also no chance finding this through the documentation (maybe internal procedure)
You need to process the message body on your own. The Outlook object model doesn't provide any property or method for that out of the box.
The Outlook object model supports three main ways of customizing the message body:
The Body property returns or sets a string representing the clear-text body of the Outlook item.
The HTMLBody property of the MailItem class returns or sets a string representing the HTML body of the specified item. Setting the HTMLBody property will always update the Body property immediately.
The Word object model can be used for dealing with message bodies. See Chapter 17: Working with Item Bodies for more information.
You can add a special MAPI property (used by Web addins, DASL name "http://schemas.microsoft.com/mapi/string/{A98A1EF9-FF40-470B-A0D7-4D7DCE6A6462}/WebExtNotifications") to show the notification banner.
Something along the following lines (VBA, you'd need to deselect and select again the currently selected message to see the change):
notificationXml = "<?xml version=""1.0""?>" & vbCrLf & _
"<Apps>"& vbCrLf & _
" <App id=""00000000-0000-0000-0000-000000000000"">"& vbCrLf & _
" <Notifications>"& vbCrLf & _
" <Notification key=""notification"">"& vbCrLf & _
" <type>0</type>"& vbCrLf & _
" <message>Test notification
with two lines</message>"& vbCrLf & _
" </Notification>"& vbCrLf & _
" </Notifications>"& vbCrLf & _
" </App>"& vbCrLf & _
" <App id=""00000000-0000-0000-0000-000000000001"">"& vbCrLf & _
" <Notifications>"& vbCrLf & _
" <Notification key=""notification"">"& vbCrLf & _
" <type>0</type>"& vbCrLf & _
" <message>Another notification</message>"& vbCrLf & _
" </Notification>"& vbCrLf & _
" </Notifications>"& vbCrLf & _
" </App>"& vbCrLf & _
"</Apps>"
set msg = Application.ActiveExplorer.Selection(1)
msg.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/string/{A98A1EF9-FF40-470B-A0D7-4D7DCE6A6462}/WebExtNotifications", notificationXml
msg.Save
I'm trying to write a add-in for MS Word. Is it possible to for a MS Word add-in to listen on specific port and send/receive http request/response? Will there be a firewall between MS Word and an application that is running outside of Word?
An Office AddIn can make HTTP requests without triggering a firewall issue (using Windows Firewall in its default configuration), but it can't listen without triggering firewall issues.
If you're making requests from inside word to a service you have living outside of Word that service may encounter Firewall issues while listening on a port.
Windows Firewall, by default blocks incoming requests. Windows Firewall is included with all versions of Windows XP SP2 or later.
See MSDN for more.
Additionally,
Function GetRateCBR(dDate As Date) As String
Dim sUrlRequest, intTry As Integer, _
strResponse As String
Dim oXMLHTTP As Object
Dim oResponse As Object
Set oResponse = CreateObject("MSXML2.DOMDocument")
'Build URL for request
sUrlRequest = _
"http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=" _
& Format(dDate, "dd.mm.yyyy") _
& "&date_req2=" & Format(dDate, "dd.mm.yyyy") _
& "&VAL_NM_RQ=" & "R01235"
'Try to get a response, 10 tries
intTry = 1
Do Until intTry > 10
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", sUrlRequest, False
oXMLHTTP.send
If oXMLHTTP.Status = 200 Then
If oResponse.loadXML(oXMLHTTP.responseText) Then _
Exit Do
End If
If Not oXMLHTTP Is Nothing Then oXMLHTTP.abort: _
Set oXMLHTTP = Nothing
DoEvents
intTry = intTry + 1
Loop
If Not oXMLHTTP Is Nothing Then oXMLHTTP.abort: _
Set oXMLHTTP = Nothing
If intTry <= 10 Then
GetRateCBR = Mid$(oResponse.Text, 3)
End If
If Not oResponse Is Nothing Then oResponse.abort: _
Set oResponse = Nothing
End Function
Example via Access Blog
People claim the following VB script works for changing network adapter names. However I am having a decidedly difficult time trying to convert this to a c# appliaction that can do the same thing. The problem I seem to be facing is that calls to the NetworkInterface.Name is readonly.
Option Explicit
Const NETWORK_CONNECTIONS = &H31&
Dim sOldName= WScript.Arguments(0)
Dim sNewName= WScript.Arguments(1)
Dim objShell, objFolder, colItems, objItem
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)
Set colItems = objFolder.Items
For Each objItem in colItems
If objItem.Name = sOldName Then
objItem.Name =sNewName
End If
Next
I found this which explains it a bit more: http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/11/how-can-i-rename-a-local-area-connection.aspx.
Ok, so there are special folders where the NIC names are stored and you access those folders by binding to the them via the SHELL. How then do you do something like this in c#?
You can change the name of a NIC easily through the registry if you know how the registry structure works.
You will need the NetworkAdapters GUID in order to locate which path to open. To get the network adapter GUID I recommend first querying the WMI "Win32_NetworkAdapter" class. There is a GUID property along with all the other properties needed to identify specific adapters.
You will notice this GUID in the registry path: {4D36E972-E325-11CE-BFC1-08002BE10318}Visit link for information on it:
http://technet.microsoft.com/en-us/library/cc780532(v=ws.10).aspx
string fRegistryKey = string.Format(#"SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{0}\Connection", NIC_GUID);
RegistryKey RegistryKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, #"\\" + Server.Name);
RegistryKey = RegistryKey.OpenSubKey(fRegistryKey, true); //true is for WriteAble.
RegistryKey.SetValue("Name", "<DesiredAdapterName>");
By design the windows UI will not allow for duplicate NIC names. However, you can force duplicate NIC names via the registry. We have done tests, there seem to be nothing critically effected by having duplicate names. Windows seems to still function fine. You just want to be wary about scripting against NIC names if you don’t incorporate anti-duplicate name logic.
To create uniqueness you can use the adapter index property associated with the WMI query.
You can use the System.Management assembly and use this class.
Follow the sample here - http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/727c8766-8189-4ad6-956d-958e52b97c05/
You can also create a VB.NET dll with the functionality you need and reference and call it from your C# code.
Here is a console app demonstrating the code (I tested and it works :)
Option Explicit On
Module Module1
Sub Main()
Const NETWORK_CONNECTIONS = &H31&
Dim sOldName = "Local Area Connection"
Dim sNewName = "Network"
Dim objShell, objFolder, colItems, objItem
objShell = CreateObject("Shell.Application")
objFolder = objShell.Namespace(NETWORK_CONNECTIONS)
colItems = objFolder.Items
For Each objItem In colItems
Console.WriteLine(objItem.Name)
If objItem.Name = sOldName Then
objItem.Name = sNewName
End If
Console.WriteLine(objItem.Name)
Next
End Sub
End Module
It prints out:
Local Area Connection
Network
We have a company application for automating certain tasks (it doesn't matter what actually). In our software we have the abbility to build a script based on our own commands, were also able to run a VBScript script within the same environment. We have a function built into the software, so we can get and set variables from a VBScript script within our own script.
In our manual we have this description: "The VB script feature provides a new VB object "AppName". One of the functions are: AppName.GetStringVariable("variable"). So by just using it like this in a VBScript script it's possible to set or get this variable. You would write it like this inside the VBScript script:
stringInput = AppName.GetStringVariable("variable")
The VBscript engine is running in a different process than the C#.NET application. So this VBscript object is running in a different process, which I would like to access in my C#.NET application.
Are there any possibility to get this variable within a C# .NET environment?
I have tried:
System.Environment.GetEnvironmentVariable("AppName.GetStringVariable(string1)");
System.Environment.GetEnvironmentVariable("AppName.GetStringVariable('string1')");
System.Environment.GetEnvironmentVariable("AppName.GetStringVariable(\"string1\")");
In the vbScript monitor a file that is updated by c# and set the property:
comp = "."
dir = "."
select = "SELECT * FROM __InstanceModificationEvent WITHIN 10 "
where = "WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent= 'Win32_Directory.Name=" & dir & "'"
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & comp & "\root\cimv2")
Set events = wmi.ExecNotificationQuery(select & where)
Do
Set event = events.NextEvent
Wscript.Echo event.TargetInstance.PartComponent
Loop
Then from c# setup a FileSystemWatcher to another file (use json, it's easy to deserialize) and get the vbScript set property.
In C# in an asmx web service how do I get the current domain that the webservice was called on?
HttpContext.Current.Request.Url.Host returns kindof what I want but instead of http://mydomain.com/Folder/Mywebservice.asmx I just need http://mydomain.com.
I know i could just cut that string up but it seems really in-elegant.
Thanks
Uri.GetLeftPart helps here:
Request.Url.GetLeftPart(UriPartial.Authority)
In VB.Net I have used...
With HttpContext.Current.Request.Url
sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host
End With
Or if you care about the Port then...
With HttpContext.Current.Request.Url
sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host & IIf(.IsDefaultPort,"",":") & .Port
End With
Should be easy to convert to C# ;)