|
Hi, I'm working in .NET 8 (not .NET Framework). Trying to programmatically create a file system link (LNK file) in C#.
I've added a reference to the Windows Script Host Object Model as detailed in many different online articles.
However, I can't seem to find the correct Using statement to import the classes in that reference.
When I say, "Using IWshRuntimeLibrary", it says it cannot resolve the type or namespace.
What must I do to import the types in the Windows Script Host Object Model reference?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
This worked fine for me in .NET 8:
using IWshRuntimeLibrary;
.
.
.
WshShell shell = new();
WshShortcut shortcut = shell.CreateShortcut(@"C:\Users\test\Desktop\Test.lnk");
shortcut.TargetPath = @"C:\Windows";
shortcut.Save();
I didn't do anything other than set the reference to the Windows Script Host Library.
|
|
|
|
|
Yes, I found that code on the web. But VS is not able to resolve IWshRuntimeLibrary even though I added the reference.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Huh.
You can try clearing the component caches. Quit VS and open the C:\Users\xxxx\AppData\Local\Microsoft\VisualStudio\version\ComponentModelCache folder and kill everything in it. Restart VS and see what happens.
If that doesn't work, there's a cache folder for Roslyn too at C:\Users\xxxx\AppData\Local\Microsoft\VisualStudio\Roslyn . Wipe that one out too.
|
|
|
|
|
<pre>I have created MSI Package using InstallShield@2014 supporting languages English - United States(1033) Chinese - Taiwan(1028)
Chinese - China(2052)
Language MST file (1033.mst, 1028.mst & 2052.mst) is embedded with MSI Package. My requirement is to update MSI Package License Agreement(EULA) for all supporting languages from any tool & Repackage MSI Package and share to end user. When end user install MSI Package he/she can see updated License Agreement(EULA) for all supporting languages.
I tried many way to update MSI Package License Agreement(EULA) but unable to find correct way to update License Agreement(EULA).
Please help me to update License Agreement(EULA) in MSI Package using C# windows application.
Thanks for any help anyone can provide.</pre>
|
|
|
|
|
You have already asked this in Quick Answers.
Don't post the same question in two places - all you will do is duplicate work and annoy people. Pick either the C# forum or the Q&A and stick with it.
Annoyed people are less likely to be helpful than happy ones...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am trying to encrypt and decrypt some text using System.Security.Cryptography.Aes.[^].
Here's my Console app:
var password = "thisIsAReallllllllyLongPasswordForTesting";
var passPhrase = "E546C8DF278CD5931069B522E695D4F2";
var initVector = "HR$2pIjHR$2pIj12";
var encrypted = Cryptography.EncryptString(password, passPhrase, initVector);
Console.WriteLine("Encrypted password");
Console.WriteLine(encrypted.ToString());
string decrypted = Cryptography.DecryptString(encrypted, passPhrase, initVector);
Console.WriteLine("decrypted password");
Console.WriteLine(decrypted);
Here's my crypto class:
public static class Cryptography
{
public static string EncryptString(string plainText, string passPhrase, string initVector)
{
string encrypted = "";
using (Aes aes = Aes.Create())
{
aes.Key = Encoding.ASCII.GetBytes(passPhrase);
aes.IV = Encoding.ASCII.GetBytes(initVector);
using (var memoryStream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
{
using (var streamWriter = new StreamWriter(cryptoStream))
{
streamWriter.Write(plainText);
}
encrypted = Encoding.UTF8.GetString(memoryStream.ToArray());
}
}
}
return encrypted;
}
public static string DecryptString(string encryptedText, string passPhrase, string initVector)
{
string decrypted;
var inputBytes = Encoding.ASCII.GetBytes(encryptedText);
using (Aes aes = Aes.Create())
{
aes.Key = Encoding.ASCII.GetBytes(passPhrase);
aes.IV = Encoding.ASCII.GetBytes(initVector);
using (var memoryStream = new MemoryStream(inputBytes))
{
using (var cryptoStream = new CryptoStream(memoryStream, aes.CreateDecryptor(), CryptoStreamMode.Read))
{
using (var streamReader = new StreamReader(cryptoStream))
{
decrypted = streamReader.ReadToEnd();
}
}
}
}
return decrypted;
}
private static void PadToMultipleOf(ref byte[] src, int pad)
{
int len = (src.Length + pad - 1) / pad * pad;
Array.Resize(ref src, len);
}
}
I don't get any errors when encrypting, but when I decrypt I get
The input data is not a complete block.'
I thought that maybe I need to pad the input array, but when I uncomment this:
PadToMultipleOf(ref inputBytes, 16);
then I get
Padding is invalid and cannot be removed.'
Anyone know what's wrong, or maybe can point me to a working example?
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
You need to pad the input buffer BEFORE encrypting it, to get the length of the encrypted text right.
There are a bunch of different things you can use for padding. Google something like "AES padding" to see what's acceptable to the implementation.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
|
Thank you
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I replied a couple of times on the post you provided
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
The variable names and string in your example suggest you are trying to encrypt a password. That is almost always the wrong thing to do.
If you're trying to write an authentication system, you should be storing a salted hash of the users' passwords, using a unique salt per record, and multiple iterations of a cryptographically-secure one-way hash. There is no way to "decrypt" the password; instead, you use the stored salt and repeat the hashing operation on the entered password, then compare it to the stored hash.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
If instead you're trying to store passwords or access keys for third-party systems, where you actually need to retrieve the original password, then you need to consider how you're going to store the encryption keys securely; how you're going to rotate them to minimize the impact if one is leaked; any many other complex issues. For example, you seem to be using a fixed IV for every value you encrypt, which is not secure.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have three windows form say form1 ,form2 and pin form.In form1 user have to input some values.There is save button in this page .By clicking on save button Pin form is opened in that we have enter the correct pin and by clicking on submit button form2 get opened.In Form2 the values that user entered in the form1 is displayed in the old values column.
And then the user go back to form1 and modify the values and click save button to come to form2. That modified values are displayed in new values column.
The problem is that when second time i modify the values in form1 and click save to go to form2,there i am getting old values of form1 but I want both old values and new values
|
|
|
|
|
Well, there's a problem in your secret code that you didn't show.
It's not entirely clear what you mean by "old values" and "new values", so I'm just going to say this. It sounds like you're not updating the new values in the form when Form2 returns. It seems you're like ignoring them, or you're using controls to store values instead of a data model, and/or you're binding controls to the wrong properties in your model.
In all cases, without seeing the code, it's impossible for anyone to tell you what you're doing wrong.
|
|
|
|
|
OK, that's not too bad if you handle it right.
Add a property to Form2 to take the value. In the property setter, set the old values column.
Then go to Form1 and open the PIN form using ShowDialog - that means that Form1 will be "frozen" until the user closes the PIN form.
Now create an instance of Form2 and store it in a class level variable. Handle the Form2.FormClosed event, and clear that variable to null in the handler.
Display Forms2 using the Show method.
In the Save button handler, check the variable: if it is null, do nothing.
Otherwise, use the property to set the new value(s).
Sounds complicated, but it's pretty simple when you get your head around it.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi
I wrote the below simple code to merge two video files, it's working. But I wanna track the merging task percentage (or something that shows the progress), so I could show it using a progress bar. How to track the progress? Thanks.
textBox_taskMsg.Text = "Task is being performed.. This may take some time.";
string[] files = { textBox_Source1.Text, textBox_Source2.Text };
string output = textBox_Source1.Text + "_merged.mp4";
var conversion = await FFmpeg.Conversions.FromSnippet.Concatenate(output, files);
await conversion.Start();
textBox_taskMsg.Text = "Merge Complete.";
|
|
|
|
|
The only way to find that out is to go back to where you got the package from, and either ask there or read the documentation. But ... if you are using ffmpeg in a separate process, it's very unlikely that progress reporting is going to be possible: ffmpeg isn't a "windows aware" app, it's a console app and those don't generally report anything except to a console screen. And while you can pipe the console app progress to a stream you can read that requires getting the process itself, and providing extra command line instructions when the process is started. Since you are using a wrapper API, it would be entirely up to what that wrapper provides, and I'm not familiar with that one.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You can use the 'OnProgress' event - ffmpeg Documentation[^]
To add a progress tracker using a percentage, add the following to your code -
textBox_taskMsg.Text = "Task is being performed.. This may take some time.";
string[] files = { textBox_Source1.Text, textBox_Source2.Text };
string output = textBox_Source1.Text + "_merged.mp4";
var conversion = await FFmpeg.Conversions.FromSnippet.Concatenate(output, files)
.OnProgress += (sender, args) =>
{
double progressPercentage = args.Percent;
textBox_taskMsg.Text = $"Merging... {progressPercentage:F2}% complete";
};
await conversion.Start();
textBox_taskMsg.Text = "Merge Complete.";
|
|
|
|
|
Hi.
I tried to merge two videos into one using Splicer library. When I ran the code (below), the code got non-responsive, so after awhile I stopped the code from executing. The resulting file (which was created by the code while it has became non-responsive) was over 11GB. I'm not sure how to fix that. Could anyone guide me please? Thanks.
--------
string[] filepaths = new string[10];
filepaths.SetValue(textBox_Source1.Text, 0);
filepaths.SetValue(textBox_Source2.Text, 1);
MergeVideos(filepaths, filepaths[0] + "_merged");
------
using (ITimeline timeline = new DefaultTimeline())
{
IGroup group = timeline.AddVideoGroup(32, 720, 576);
var firstClip = group.AddTrack().AddVideo(videoPaths[0]);
var secondClip = group.AddTrack().AddVideo(videoPaths[1], firstClip.Duration );
using (AviFileRenderer renderer = new AviFileRenderer(timeline, outputFilePath))
{
renderer.Render();
}
}
modified 6-Mar-24 0:33am.
|
|
|
|
|
The only person who's going to be able to "guide you" on this is the person(s) who wrote the Splicer library.
As far as I can tell, there is no documentation on it that survives anywhere and the project on GitHub hasn't been touched in the last 6 years.
It appears to be abandoned.
|
|
|
|
|
To add to what Dave has said, if you are recoding videos in order to join them together (and unless they have the same resolution, same frame rate, same codecs, and a very similar bit rate that is exactly what you have to do to get a working file) then it's going to take some significant time - we are talking hours here for 4K videos, even on a powerful machine, using well optimised software. The partial file size of 11GB isn;t that surprising in the context of the bitrate you appear to be requesting: is that "32" generating a 32K bitrate? If so, then the file size is going to be pretty huge and will take a long time to process.
Grab a free copy of XMedia Recode[^] (it's one of the tools I use for such jobs) and see how long it takes and the resulting video file size.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks.
The two files I'm trying to merge are around 30MB each. I'm actually not that familiar with working videos in C#, just playing around and testing here. Anyways, a video merger like Wondershare would take less than 5 mins to do it, and the resulting video would be less than 100MB. I'm not sure how to properly do that.
|
|
|
|
|
Check the bitrate on the result file from wondershare (windows explorer will show you that) and use VLC to check the codecs the result file contains - H265 for example is a lot more compact than H264 for example, but not everything can read it.
But as Dave said, that one would appear to be abandoned - and that may be because it was never finished, or had bugs, or ... you never know.
You know you can splice files directly using FFMPEG as an external process? Concatenate – FFmpeg[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have this block of code
try
{
_clientContext = new ClientContext(baseUrl);
_clientContext.Credentials = new SharePointOnlineCredentials(userName, Password.GetSecureString(password));
_clientContext.Load(_clientContext.Web, w => w.ServerRelativeUrl);
_clientContext.ExecuteQuery();
}
catch (Exception e)
{
throw;
}
The code stops for about 20-25 seconds on the ExecuteQuery line. If I paste the URL into a browser it loads quicly, so I know that's not the problem. No error is thrown. It's just really slow.
All subsequent calls to the server after that are ok. It's on this first calls that is really slow.
Can anyone shed some light on this? I'm not really sure how to debug this.
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
modified 2-Mar-24 19:34pm.
|
|
|
|
|