Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a requirement where I have to add computer name to the pre-defined active directory group. Does anyone have experience related to this ?
You can do this through C# code using System.DirectoryServices
// Bind to the Computers container and add a new computer.
DirectoryEntry de01 = new DirectoryEntry("LDAP://CN=Computers,DC=fabrikam,DC=com");
DirectoryEntry newComputer = de01.Children.Add("CN=New Computer", "computer");
newGroup.CommitChanges();
See http://msdn.microsoft.com/en-us/library/ms180832(v=VS.90).aspx for examples.
Use ADSI. Basically you bind to the Active Directory, locate the computer object and group object you need, and call a method to add the computer to the group.
If it needs to be from a command line, you can easily do this using WSH or .Net.
ADSI reference:
http://msdn.microsoft.com/en-us/library/aa772218(v=VS.85).aspx
ADSI LDAP:
http://msdn.microsoft.com/en-us/library/aa746384(v=VS.85).aspx
It will not take effect until the computer reboots.
Below code worked for me
//Step 1: get the DN of the adgroup you want to use
DirectoryEntry groupEntry = new DirectoryEntry ("LDAP://CN=AdgroupNameWewantToAddTo,DC=na,DC=ABCint,DC=com");//adgroupDSN
//step 2: get the Dn of the pc you want to add to the group
string memberDN;
DirectorySearcher dom = new DirectorySearcher(baseDN);
dom.Filter = "(&(ObjectCategory=computer) (cn=" + PCNAME+ "))";
SearchResult searchResult = dom.FindOne();
if (searchResult != null)
{
memberDN=searchResult.GetDirectoryEntry().Path;
}
//Step 3:add PC to the ad group
groupEntry.Invoke("Add", computerdn);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
in order to enable multiple credentials to my application - I want to use custom environment variable for each.
how can I set it explicitly?
in GCP docs I see only this default option.
Edit:
the libraries I'm using are Google.Cloud.Storage.V1 and Google.Apis.Dataflow.v1b3
I succeeded by using this
var credentials = GoogleCredential.FromFile(#"c:\certs\sa.json");
var storageClient = StorageClient.Create(credentials);
If you use the default credential creation, only this environment variable is possible
(example in python)
import google.auth
credentials, project_id = google.auth.default()
Now, think at the value that you put in the GOOGLE_APPLICATION_CREDENTIALS env var. It's simply a path to a service account key file. So, you can do that, which is equivalent to the previous command
import google.auth
credentials = service_account.Credentials.from_service_account_file(os.getenv('GOOGLE_APPLICATION_CREDENTIALS'))
And thus, you can use the env var name that you want and create an explicit credential by passing the path to the correct file!
Example in C#:
var credentials = GoogleCredential.FromFile(#"c:\certs\trigger-sa.json");
var storageClient = StorageClient.Create(credentials);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm fairly new to WebDAV , how do I go about coding in vb or C# to automap a network drive and check if letter G:\ is available and if it is , assign that letter, if not go to H , I, J ,K drives ?
thank you in advance
You can start a process to add the network drive. Then you can check to see when and how p finishes.
Dim p As Process
p = System.Diagnostics.Process.Start("net.exe", "use r: \\reo\c-drive")
Here is one way to check the availability of a drive letter:
If System.IO.Directory.Exists("c:\") Then ...
You can also use Windows API calls, which are messier to write but don't require a separate process.
It's usually not necessary to map a network drive, however, because you can generally use the network path instead of the mapped drive letter.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I use this code blow in .NET. It works fine. The problem is that I want this audio to play in the root of the website. What changes should I make for this? Thanks
var sample= new System.Windows.Media.MediaPlayer();
sample.Open(new System.Uri( #"D:\voices\1.wav");
sample.Play();
In a web application, this might look something like this:
sample.Open(new System.Uri(Server.MapPath("~/") + #"\voices\1.wav");
I say might because that all depends on whether or not the voices folder exists in the root of the website. Additionally, you should probably leverage Path.Combine instead:
var path = Path.Combine(Server.MapPath("~/"), "voices", "1.wav");
sample.Open(path);
Finally, I don't know what sample is, but the Open method may not work in a website. I'm making the assumption you know what Open does and whether or not it can work in a website.
Use server.mappath("~/") <- that's the filesystem root for your website.
dim path as string = server.mappath("~/") & "/voices/1.wav"
Note that backslashes, for filesystem path, not URI.
Hope it helps.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have created a WindowsApp.exe under Application\Setup folder. Now I want to create a Database under Application\Database folder from WindowsApp.exe
What should be the path given to the filename here?
try
Path.Combine(Environment.CurrentDirectory, "Database\\db1.mdb")
Edit
since you want the parent folder you can go up one folder by doing
Path.Combine(Environment.CurrentDirectory.Substring(Environment.CurrentDirectory.LastIndexOf("\\")), "Database\\db1.mdb")
Edit 2
if you want the Application folder even if its N times above the current folder then you can reach it by doing this
var index = Environment.CurrentDirectory.IndexOf(Environment.CurrentDirectory.IndexOf("ApplicationRootFolderName"),"\\")
var AppRootPath = Environment.CurrentDirectory.Substring(0,index);
Edit 3
As mentioned by Michael its better to get the parent folder using this way
Directory.GetParent(Environment.CurrentDirectory).FullName
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I wish to make all my save transactions at the same time.
I'm using Subsonic 3.0 with active record. I've seen some post with MyClassCollection.Save();
However when i "Run Custom tool" i don't get collections. Obviously i'm missing a trick here?
There is of course another way to do this, using BatchQuery. I had an issue with this. Appreciate any thoughts, as you can see i've very new too all this.
var provider = ProviderFactory.GetProvider("MyProvider");
var batch = new BatchQuery(provider);
foreach (var cdnEntry in cdnEntries)
{
var query1 = new Insert(provider).Into<Clip>
("Author").Values(
cdnEntry.Author);
batch.QueueForTransaction(query1);
}
batch.ExecuteTransaction(); // nothing happens as query count alway = 0
I obviously need to read on the different patterns available for subsonic. Tho i have got the batchquery working. The above code works. I had few silly sql typo's giving me grief.