|
What is contained in command1 and command2 in your code snippet? And what results or errors do you see?
|
|
|
|
|
I should have removed the command1 and command2, those were just additional ways of me trying the same thing. Sorry about that.
Error message is
Quote: - The term 'Import-Module' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. - System.Management.Automation - at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings) at System.Management.Automation.PowerShell.Invoke(IEnumerable input) at System.Management.Automation.RemotePipeline.Invoke(IEnumerable input) at System.Management.Automation.Runspaces.Pipeline.Invoke() at exchangePictureUpdater.exchangePictureUpdater.btnAddReplace_Click(Object sender, EventArgs e) - Void CoreInvoke[TOutput](System.Collections.IEnumerable, System.Management.Automation.PSDataCollection`1[TOutput], System.Management.Automation.PSInvocationSettings) |
Command command1 = new Command("set-adserversettings");
CommandParameter parameter1 = new CommandParameter("viewentireforest", true);
command1.Parameters.Add(parameter1);
Command command2 = new Command("set-userphoto");
CommandParameter parameter2a = new CommandParameter("identity", tbxName.Text);
CommandParameter parameter2b = new CommandParameter("picturedata", displayedImage);
CommandParameter parameter2c = new CommandParameter("domaincontroller", "adfadfadf.com");
CommandParameter parameter2d = new CommandParameter("confirm", false);
command2.Parameters.Add(parameter2a);
command2.Parameters.Add(parameter2b);
command2.Parameters.Add(parameter2c);
command2.Parameters.Add(parameter2d);
Pipeline pipeline = runspacee.CreatePipeline();
pipeline.Commands.Add(command1);
pipeline.Commands.Add(command2);
|
|
|
|
|
|
results = pipeline.Invoke()
I need a working example of how to do this, and after that I can modify it to my own needs
|
|
|
|
|
Here is what I ended up doing, this allows me to create a script in a string with multiple commands, it processes 1 command at a time and then creates a runspace in c# and runs all of the powershell commands
string scriptText = @"$pw = convertto-securestring -AsPlainText -Force -String '<password>'; $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist '<domain>\<username>', $pw; $session = new-pssession -ConfigurationName Microsoft.Exchange -ConnectionUri '<server url>/powershell' -credential $cred; import-pssession $session; Set-ExecutionPolicy bypass -confirm:$false -force; $pic = ([System.IO.File]::ReadAllBytes('" + <picture file name> + "')); set-userphoto -identity <username> -picturedata $pic -domaincontroller '<dc fqdn>' -confirm:$false;";
runExchangeShellScript(scriptText);
private string runExchangeShellScript(string scriptText)
{
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
RunspaceInvoke runSpaceInvoker = new RunspaceInvoke(runspace);
runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
Collection<PSObject> results = null;
try
{
results = pipeline.Invoke();
}
catch (Exception ex)
{
MessageBox.Show(ex.InnerException + " - " + ex.Message + " - " + ex.Source + " - " + ex.StackTrace + " - " + ex.TargetSite + " - " + ex.Data);
return "";
}
runspace.Close();
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
return stringBuilder.ToString();
}
|
|
|
|
|
Suppose you have two forms: frmMain and frmPopup, on frmMain has 1 button (the button) click open frmPopup, on frmPopup many (button), you click on the button any frmPopup button will transmit data by the delegate of copper frmMain frmPopup before closing time announced new open yes / no of MessageBox.Show. When your done click the close button again poup frmPopup then MessageBox.Show on frmPopup, frmPopup refused to play, until the click buttons yes/no of MessageBox.Show, click the button here as yes / no, then frmPopup and MessageBox. Show it to close. I want to play a new fat frmPopup MessageBox.Show done. Their code has the following structure:
[code]
//Declare frmMain
public partial class frmMain : Form
{
private void getData(data)
{
if (conditions) Updata();
}
public frmMain()
{
InitializeComponent();
}
private void cmdfrmPopup_Click(object sender, EventArgs e)
{
frmPopup frm = new frmPopup(data);
frm.Data = getData;
frm.ShowDialog();
}
private void Updata()
{
DialogResult dlgRes;
string sAskUser = "Are you sure delete ?" ...
dlgRes = MessageBox.Show(sAskUser, "warning..", MessageBoxButtons.YesNo, Question);
if (dlgRes == DialogResult.OK)
{
}
}
}
//Khai báo frmPoup
public partial class frmPopup : Form
{
public frmPopup(nhandulieuden)
{
InitializeComponent();
}
private void cmdButton1_Click(object sender, EventArgs e)
{
Process();
}
private void cmdButton2_Click(object sender, EventArgs e)
{
Process();
}
private void cmdButton3_Click(object sender, EventArgs e)
{
Process();
}
private void cmdButton4_Click(object sender, EventArgs e)
{
Process();
}
private void Xuly()
{
this.Close();
transmissionOffrmMain(data);
}
private void cmdExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
[/code]
through available tracks your household help this place.
|
|
|
|
|
If your message does not appear immediately, do not repost it again, and again, and again...
Your original post was sent to moderation by the automated spam detector, and it took a human (or in this case me) to decide to approve or reject it for publication. And to avoid giving you a severe kicking as a spammer, I had to let all of them through and then go clean up after you later. Which is a waste of my time!
If it doesn't post immediately, give it a few moments - we work as fast as we can, but we are all volunteers with other demands on our time.
I've deleted the three spare version of this...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
hello people of code project i have the following code.
private String header;
private Dictionary<String, String> tokens;
public DevExpress.XtraEditors.TextEdit txtDisplayName;
public DevExpress.XtraEditors.ListBoxControl lstwep;
public DevExpress.XtraEditors.SimpleButton elfenliedbutton;
public DevExpress.XtraEditors.TextEdit txtmaxammo;
public LauncherForm elfform;
private String file;
public Parser(String file, DevExpress.XtraEditors.ListBoxControl lstelfen, LauncherForm elfform1)
{
elfform = elfform1;
lstwep = lstelfen;
this.file = file;
String plainText;
using (StreamReader sr = new StreamReader(file))
{
plainText = sr.ReadToEnd();
}
String[] tokens = plainText.Split('\\');
this.tokens = new Dictionary<string, string>(tokens.Length + 10);
header = tokens[0];
for (int i = 1; i < tokens.Length; i += 2)
{
String key = tokens[i];
String val = (i + 1 <= tokens.Length) ? tokens[i + 1] : "";
this.tokens.Add(key, val);
}
}
public String Search(String name)
{
foreach (KeyValuePair<String, String> pair in tokens)
{
if (pair.Key == name)
return pair.Value;
}
return null;
}
public void Set(String key, String val)
{
tokens[key] = val;
}
public void Save(String file)
{
using (StreamWriter sw = new StreamWriter(File.OpenWrite(file)))
{
sw.Write(header);
foreach (KeyValuePair<String, String> pair in tokens)
{
sw.Write("\\" + pair.Key + "\\" + pair.Value);
}
}
}
public void Save()
{
this.Save(file);
}
}
what i want to do is generate a list box with all weapon files in a mod and when one is selected it will execute the parse code
here is a little muck up i made in gui to explain better what i mean
http://i.imgur.com/khoG06h.png[^]
as you can see form below code i can get the file to parse but i want to load all the weapon file names form directory and list them all in the listbox then when i select a name it will load the weapon file into selected boxes
but im not sure how to do this i managed to get it to work with push of a button but i cant seem to get it to list weapon files into the listbox and then on a select it will run the code to load the selected weapon file and then display its values to text box then save it out. and here is the one example weapon file so its easy to understand what im trying to do.
MEGA[^]
so form example weapon file for example displayName/weaponname/ thats how they are layied out
thank you in advance elfenliedtopfan5
|
|
|
|
|
Since you appear to have the code to read from a file, all you need to do is list the relevant files into a list box - which is pretty much trivial to do:
private void LoadFileNames(string folder, string extension, ListBox lb)
{
string[] files = Directory.GetFiles(folder, "*" + extension);
lb.DataSource = files.Select(f => Path.GetFileNameWithoutExtension(f)).ToList();
}
All you need to do is ensure that your "weapons" files have a unique extension and call the method:
LoadFileNames(@"D:\Temp", ".txt", myListBox);
When the user selects a file, pull the file name from the list box, put the extension back on, and use Path.Combine to add the folder back in.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you for your response when i try to add in the list box name it wont add in the reverence i made and still at a little loss on how to execute this code to work right if that makes sense
image shows error.
http://i.imgur.com/hnung0v.png[^]
|
|
|
|
|
So what is "lstwep" when it's at home? It isn't a standard class - so I have no idea where you would find it!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
lstwep is what i named the listbox lst is short for listbox
|
|
|
|
|
So why did you change what I wrote and replace the class name with a variable name?
That is just like writing this:
string greetings = "Hello!";
private void MyMethod(greetings g)
{ Instead of:
string greetings = "Hello!";
private void MyMethod(string g)
{
...
}
...
MyMethod(greetings);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
bit i still get a issue when i add this in thats why i tried my best to remove this error
and i thout changing the name form listbox to elfwep witch is the name of my listbox but it still gives me the below error showed in the picture.
http://i.imgur.com/c6JH6TH.png[^]
|
|
|
|
|
That's because you don't have the using statement in your class...
using System.Windows.Forms;
You are supposed to know this stuff!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
lol yeah slipped my mind feel so stupid now ;( but how would i use that in the code i already have as in when i push a button it will load all the stuff into a listbox with the code you provided to me ? sorry im such a noob.
|
|
|
|
|
Interestingly, I couldn't find anything on this when I googled it. I have a ContextMenu with MenuItems and I want each MenuItem to have their own ContextMenu so I can both left and right click them. Trouble is, when I have code like this:
<MenuItem ContextMenu="{StaticResource MyContextMenu"/>
Right clicking on the MenuItem closes the MenuItem's parent ContextMenu instead of showing the MenuItem's ContextMenu. I've also experimented with adding StaysOpenOnClick="True" , but to no effect.
How can I do this?
|
|
|
|
|
What is wrong to simply add sub items for the "main" menu items?
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I already do do that. The point is for the MenuItem to have children AND it's own ContextMenu. Google Chrome's bookmarks bar is a perfect example and clearly the logic is different than what you're suggesting.
I want this:
<MenuItem ContextMenu="{StaticResource MyContextMenu}">
<MenuItem/>
<MenuItem/>
<MenuItem/>
</MenuItem>
Obviously, I'm aware of submenus, but it's not quite the same.
|
|
|
|
|
I see and need to have a look to Chrome's bookmarks.
I made also some tests with WPF and was not able to make a ContextMenu for a "parent" ContextMenu item. I found that also RightClick the parent menu item ends in OnClick, which seems again to be an exceptional behaviour only for menu items.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Starting to suspect Chrome might only be using one menu for each bookmark and the bar itself. It looks like they enable/disable certain items depending on what's clicked. So if it's just one of those things you can't do, I'm cool with that. Just have to rethink what I want to do.
|
|
|
|
|
Strictly speaking, a ContextMenu is just an adorner - it should be possible for you to roll your own adorner abstraction to do what you want.
This space for rent
|
|
|
|
|
I'm with 0x01AA on this, use a sub menu, left click on a menu item is not intuitive and is probably not supported.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a class that has no parameters then i will create an object of it and convert it to stream and store it into a dictionary, every thing is fine until i add parameter to the class.
basically i do this.
var classObject = new ClassObject();
dictionary.Add(id, new MemoryStream());
then i will just retrieve it like this.
var retriveObject = dictionary[id] as ClassObject;
Now I add a single parameter on that class now using the last code above will produce Quote: no parameterless constructor defined for this object
my question, is there way to fix the exception without removing the parameter i added to the class?
Thanks
|
|
|
|
|
Gilbert Consellado wrote: is there way to fix the exception without removing the parameter i added to the class
Which implies that your code sample doesn't reflect the current code:
var classObject = new ClassObject(); Has been changed to something like
var classObject = new ClassObject(myParameterValue); And the class constructor changed to something like
public classObject(SomeClass parameterName)
{
... As a result, the class no longer contains a parameterless constructor as the error message indicates.
Create a new constructor:
public classObject()
{
... And it should get rid of the error.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|